Android xml中的ImageButton(图像太小,分辨率太差)
我有以下3个图像按钮。下面代码的显示方式,三个按钮看起来是一样的。 问题:Android xml中的ImageButton(图像太小,分辨率太差),android,android-linearlayout,imagebutton,Android,Android Linearlayout,Imagebutton,我有以下3个图像按钮。下面代码的显示方式,三个按钮看起来是一样的。 问题: 图像没有完全填满按钮的大小 图像的分辨率很差。我将图像保存在所有res/drawable文件夹(drawable hdpi、mdpi等)中。图像由“Android图标集”向导加载 有什么想法吗?我一直在玩padding和scaleType,因为我在其他帖子中看到它们是解决方案 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical">
<ImageButton
android:id="@+id/abutton"
android:src="@drawable/a_button_icon"
android:layout_height="150dp"
android:layout_width="150dp"
android:padding="5dp"
android:scaleType="fitXY"/>
<ImageButton
android:id="@+id/button"
android:src="@drawable/b_button_icon"
android:layout_height="150dp"
android:layout_width="150dp"
android:scaleType="fitXY"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="10dp">
<ImageButton
android:id="@+id/cbutton"
android:src="@drawable/d_icon"
android:layout_height="150dp"
android:layout_width="150dp"
android:padding="20dp"
android:scaleType="fitXY"/>
<ImageButton
android:id="@+id/dbutton"
android:src="@drawable/about_a_button"
android:layout_height="150dp"
android:layout_width="150dp"
android:padding="20dp"
android:scaleType="fitXY"/>
</LinearLayout>
</LinearLayout>
不要将drawable分配给
android:src
属性,而是将其分配给ImageButton
的android:background
属性
或
您可以尝试设置android:adjustViewBounds=“true”
,这将使ImageButton
调整其边界,以保留其可绘制图像的纵横比
PS:如果您将图像设置为ImageButton的背景,那么图像将缩放到ImageButton的任何大小。除此之外,src是前景图像,而背景是背景图像
编辑:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<!-- The two linear layouts will have equal widths. -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:padding="5dp" >
<!-- The two image button will fill the linear layout along width and have height 150dp -->
<ImageButton
android:id="@+id/abutton"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/engage_down" />
<ImageButton
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_marginTop="10dp"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/engage_down" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:padding="5dp" >
<ImageButton
android:id="@+id/cbutton"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/engage_down" />
<ImageButton
android:id="@+id/dbutton"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_marginTop="10dp"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/engage_down" />
</LinearLayout>
</LinearLayout>
希望这有帮助。试试看
通过删除填充并将背景设置为“null”。
就分辨率而言,我认为这是拍摄低分辨率图像
<ImageButton
android:id="@+id/dbutton"
android:src="@drawable/about_a_button"
android:layout_height="150dp"
android:layout_width="150dp"
android:background="@null"
android:scaleType="fitXY"/>
我也面临同样的问题。没有其他人为我工作。最后,这是一个简单的问题。默认情况下,ImageButton周围存在填充。因此,请使用:
<ImageButton>
...
android:padding="0dp"
...
</ImageButton>
...
android:padding=“0dp”
...
它将解决问题。这可能有助于解决问题?那么图标为什么没有占据整个按钮的大小呢?但是你正在使用的图像的大小是多少?因为我总是使用我想要的并且从不需要缩放的精确大小:fitXY。更改为android:background只会删除图像按钮的背景(而不是变灰,它与背景匹配)。实际图像仍然是同一面。android:adjustViewBounds=“true”对我来说没有任何改变。还有其他想法吗?这不会改变任何事情。太奇怪了,谢谢你,反正它解决了我的问题