在LinearLayout中,我試圖使用數字圖像顯示整數。我希望數字居中,圖像的大小取決於有多少數字。使用LinearLayout顯示可變數量的圖像
我最初的佈局與2個數字:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<view
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:gravity="center"
>
<ImageView
app:srcCompat="@drawable/ic_digit_0"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_weight="1"
/>
<ImageView
app:srcCompat="@drawable/ic_digit_0"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_weight="1"
/>
</LinearLayout>
這裏是什麼樣子。
A)4位數,一切看起來不錯,數字水平適合,儘可能垂直。
B)多了很多數字,但它仍然很好地擴展到可用空間。
C)但是,當的LinearLayout高度減小時,4位分離和間隙在它們之間出現。
d)通過從每個的ImageView除去layout_weight中,4位回到一起。
E)但是,當的LinearLayout高度增加,數字刻度到視圖的整個高度和水平一些消失關閉屏幕。
我怎麼能有這些數字圖像調整大小以填充可用空間,顯示所有的數字和無間隙爲中心,同時保留其規模的比例,無論的LinearLayout尺寸的?
謝謝。
已嘗試android:scaleType根據您的要求嘗試其屬性 – Pavan
給定imageview的固定大小!使用scaletype- – xbadal
scaleType似乎不起作用。 fitXY拉伸或壓縮圖像,使其比例改變比例。修復圖像大小需要根據數字位數進行代碼計算。 –