我有LinearLayout一列中有六個水平按鈕的串列。
每個都有這樣的結構:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_menu_charge" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@ id/view_top_up_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:fontFamily="@font/montserrat_bold"
android:gravity="center_vertical"
android:text="@string/menu_pay_charge"
android:textColor="@color/black"
app:drawableEndCompat="@drawable/ic_arrow_right_small_black" />
</LinearLayout>
問題是每個串列元素都有自己的大小,我無法獲得完美的列
如何為每個設定固定大小ImageView(不增加可繪制大小)?
uj5u.com熱心網友回復:
你需要給ImageView一個固定的寬度,例如:
<ImageView
android:layout_width="64dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_menu_charge" />
或者,您可以使用layout_weight,例如:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_menu_charge" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@ id/view_top_up_button"
android:layout_width="0dp"
android:layout_weight="1.5"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:fontFamily="@font/montserrat_bold"
android:gravity="center_vertical"
android:text="@string/menu_pay_charge"
android:textColor="@color/black"
app:drawableEndCompat="@drawable/ic_arrow_right_small_black" />
</LinearLayout>
uj5u.com熱心網友回復:
打開影像并更改為相同的大小,然后再次將它們添加到可繪制物件中
試試看
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/452485.html
