【问题标题】:Android button background image sizeAndroid 按钮背景图片大小
【发布时间】:2014-06-20 22:57:58
【问题描述】:

我创建了一个个人键盘并将背景图像设置为其中一个按钮,但之后按钮大小(与我的背景)彼此不同。

<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

【问题讨论】:

标签: android android-button


【解决方案1】:

我建议你:

  1. 稍微改变你的drawable - 移除橙色矩形背景,只保留透明背景的箭头(从现在开始我将使用名称shift_off_arrow作为描述的drawable的名称)。透明背景应该只有保持整个箭头所需的大小。不是更大。

  2. 定义一种新颜色 - 橙色背景的颜色(从现在开始,我假设您已经定义了它,我将使用名称 orange_background

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

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

【讨论】:

  • 不幸的是,您的回答没有帮助。我用以下代码解决了这个问题
猜你喜欢
  • 1970-01-01
  • 2015-10-27
  • 1970-01-01
  • 1970-01-01
  • 2021-04-04
  • 2017-03-07
  • 2013-03-05
  • 1970-01-01
  • 2015-09-09
相关资源
最近更新 更多