[英]Android button background image size
我創建了一個個人鍵盤並將背景圖像設置為其中一個按鈕,但之后按鈕大小(與我的背景)彼此不同。
<Button
android:id="@+id/buttonShift"
android:paddingTop="0dip"
android:textSize="22sp"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:textStyle="bold" />
設置背景:
<Button
android:id="@+id/buttonShift"
android:background="@drawable/sym_keyboard_shift_off"
android:paddingTop="0dip"
android:textSize="22sp"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:textStyle="bold" />
請看按鈕的屏幕
前:
后:
圖像尺寸:106x68
我建議你:
稍微更改您的可繪制對象 - 移除橙色矩形背景,僅保留具有透明背景的箭頭(從現在開始,我將使用名稱shift_off_arrow作為描述的可繪制對象的名稱)。 透明背景應僅與保持整個箭頭所需的一樣大。 不是更大。
定義一個新顏色 - 你的橙色背景的顏色(從這一刻起,我假設你已經定義了它,我將使用名稱orange_background )
使用 ImageButton 而不是 Button (就像 satnam singh 和 Hamid Shatu 在對您的問題的評論中所說的那樣)
使用這樣的代碼(使用所有填充操作以獲得與您想要的完全相同的箭頭大小):
<ImageButton
android:id="@+id/buttonShift"
android:background="@color/orange_background"
android:src="@drawable/shift_off_arrow"
android:paddingTop="0dip"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.