繁体   English   中英

Android 按钮背景图片大小

[英]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

我建议你:

  1. 稍微更改您的可绘制对象 - 移除橙色矩形背景,仅保留具有透明背景的箭头(从现在开始,我将使用名称shift_off_arrow作为描述的可绘制对象的名称)。 透明背景应仅与保持整个箭头所需的一样大。 不是更大。

  2. 定义一个新颜色 - 你的橙色背景的颜色(从这一刻起,我假设你已经定义了它,我将使用名称orange_background

  3. 使用 ImageButton 而不是 Button (就像 satnam singh 和 Hamid Shatu 在对您的问题的评论中所说的那样)

  4. 使用这样的代码(使用所有填充操作以获得与您想要的完全相同的箭头大小):

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM