简体   繁体   English

Android 按钮背景图片大小

[英]Android button background image size

I created a personal keyboard and set the background image to the one of the buttons, but after that button size (with my background) is different from one another.我创建了一个个人键盘并将背景图像设置为其中一个按钮,但之后按钮大小(与我的背景)彼此不同。

<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" />

Set background:设置背景:

<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" />

Please, see the screen of the buttons请看按钮的屏幕

Before:前:

在此处输入图片说明

After:后:

在此处输入图片说明

Image size: 106x68图像尺寸:106x68

I would advise you to:我建议你:

  1. Change your drawable a bit - remove the orange rectangle background, keep only the arrow with transparent background (from now on I will use the name shift_off_arrow as a name of described drawable).稍微更改您的可绘制对象 - 移除橙色矩形背景,仅保留具有透明背景的箭头(从现在开始,我将使用名称shift_off_arrow作为描述的可绘制对象的名称)。 The transparent background should be only as big as it is needed to keep the whole arrow.透明背景应仅与保持整个箭头所需的一样大。 Not bigger.不是更大。

  2. Define a new color - the color of your orange background (from this moment I will assume you have defined it and I will be using name orange_background )定义一个新颜色 - 你的橙色背景的颜色(从这一刻起,我假设你已经定义了它,我将使用名称orange_background

  3. Use ImageButton instead of Button (just like satnam singh and Hamid Shatu said in a comments to your question)使用 ImageButton 而不是 Button (就像 satnam singh 和 Hamid Shatu 在对您的问题的评论中所说的那样)

  4. Use code like this (manipulate with all paddings to get the size of the arrow exactly like you want):使用这样的代码(使用所有填充操作以获得与您想要的完全相同的箭头大小):

<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