Zer*_*ero 46 android padding imagebutton
在我正在开发的应用程序中,我有几个ImageButtons.每个ImageButton都有一个drawable形式的背景和内容.现在drawable在ImageButton的范围内处于最大尺寸,但我希望它缩小,所以我需要添加一些填充.问题在于,当我尝试这样做时,它没有任何效果.我的XML对于每个ImageButton如下:
<ImageButton
android:id="@+id/button_zero"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dip"
android:src="@drawable/button_zero"
android:background="@drawable/button_background" />
Run Code Online (Sandbox Code Playgroud)
任何想法为什么填充不做任何事情?
完整的XML代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#222222"
tools:context=".Main" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- Row One -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/button_zero"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dip"
android:src="@drawable/button_zero"
android:background="@drawable/button_front" />
<ImageButton
android:id="@+id/button_one"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dip"
android:src="@drawable/button_one"
android:background="@drawable/button_front" />
<ImageButton
android:id="@+id/button_two"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dip"
android:src="@drawable/button_two"
android:background="@drawable/button_front" />
<ImageButton
android:id="@+id/button_three"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dip"
android:src="@drawable/button_three"
android:background="@drawable/button_front" />
<ImageButton
android:id="@+id/button_four"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dip"
android:src="@drawable/button_four"
android:background="@drawable/button_front" />
</LinearLayout>
... same for other rows
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Goo*_*iec 110
您必须添加到您的ImageButton定义
android:scaleType="fitCenter"
Run Code Online (Sandbox Code Playgroud)
或其他scaleType,如fitXY,因为默认情况下图像尝试尽可能地缩放并忽略填充
填充仅对属性有效android:src,对android:background.
将第一个设置为按钮图像,将后者设置为android:background="@android:color/transparent"
| 归档时间: |
|
| 查看次数: |
19696 次 |
| 最近记录: |