導航:首頁 > 操作系統 > androidlayout自適應高度

androidlayout自適應高度

發布時間:2023-08-28 05:42:06

android怎麼設置自適應大小的背景圖片

需要給你的ImageView布局加上Android:adjustViewBounds="true"

<ImageView android:id="@+id/test_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_launcher" />

然後,在代碼里設置ImageView.最大寬度和最大高度,因為adjustViewBounds屬性只有在設置了最大高度和最大寬度後才會起作用

int screenWidth = getScreenWidth(this);
ViewGroup.LayoutParams lp = testImage.getLayoutParams();
lp.width = screenWidth;
lp.height = LayoutParams.WRAP_CONTENT;
testImage.setLayoutParams(lp);

testImage.setMaxWidth(screenWidth);
testImage.setMaxHeight(screenWidth * 5); 這里其實可以根據需求而定,我這里測試為最大寬度的5倍

㈡ android開發軟體如何做到自適應屏幕大小及不同解析度的手機

  1. 代碼中盡量不要設置控制項的寬高(盡量使用match_parent或者wrap_content)

  2. 即使某些時候要一定要設置控制項的大小,那也要用(控制項用dp,字體用sp)

  3. 圖片要分多套設計,mdpi里放320*480的;hdpi里放480*800的;xhdpi放720*1280的;xxhdpi里放1080*1920大小的

  4. 某些時間需要按屏幕大小平分的,使用android:layout_weight=""這個屬於來平分


不明白郵件我

㈢ Android EditText當輸入文字換行後,如何讓EditText的高度也隨之適應整個文字的高度呢

我也遇到同樣問題,以下是我解決問題方法,僅供參考。
默認EditText設置warp-content就可以,但是我一直不可以,最終發現是布局有問題,因為在editText中設置了gravity="center_vertical",所以一直被截一半,導致顯示不全,後來我改成了layout_gravity="center_vertical" 就可以了,這是我全部的代碼,我設置了最多字數,你可以不限制
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:background="@color/white">

<TextView
style="@style/style_left_title_light_color"
android:layout_width="80dp"
android:layout_height="45dp"
android:text="備注" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:background="@color/white"
android:textSize="16dp"
android:textColor="@color/colorPayBtn"
android:textColorHint="@color/colorLightGray"
android:hint="請填寫備注"
android:maxLength="50" />
</LinearLayout>
style:
<style name="style_left_title_light_color">
<item name="android:layout_height">match_parent</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textSize">16dp</item>
<item name="android:textColor">@color/gray</item>

</style>

㈣ android如何設置圖片自適應控制項大小

<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ic_launcher"/>

寬度和高度使用fill_parent (填充父窗體)

fill_parent 可以使控制項充滿父控制項,也就是你說的自動使用圖片控制項外的控制項大小。

㈤ Android 自定義View 寬高總是充滿父容器,怎麼讓它自適應保持對應寬高

自定義View,想要自定義給定寬和高,你要寫自定義屬性,然後在xml文件中指定寬高才會有效,同時當給定的寬和高的值是wrap_content 或 fill_parent 這類的,這時需要在自定義View中重櫻茄寫onMeasure方衡頌慧法咐答,進行控制項的寬高測量。

閱讀全文

與androidlayout自適應高度相關的資料

熱點內容
word轉pdf用什麼軟體 瀏覽:318
安卓如何設置蘋果鬧鈴 瀏覽:266
如何修改網站後台伺服器數據 瀏覽:117
手機樂園java 瀏覽:895
二手車搬運工app哪個好 瀏覽:477
怎麼編成一個mc伺服器 瀏覽:199
施工壓縮工期 瀏覽:552
python導入包代碼 瀏覽:60
武漢解壓體驗館創業 瀏覽:983
如何弄到一個伺服器 瀏覽:805
psp里的文件夾怎麼刪除 瀏覽:647
安卓手機如何在鎖屏的情況下拍攝視頻 瀏覽:459
安卓為什麼不能安裝procreate 瀏覽:529
如何修復王者榮耀的伺服器 瀏覽:654
javaif多個條件 瀏覽:506
顯示pdf縮略圖 瀏覽:533
奇跡移動命令圖片 瀏覽:857
多玩怎麼開到伺服器 瀏覽:656
基於單片機的水塔水位控制系統設計 瀏覽:480
yd什麼伺服器 瀏覽:520