-2
嗨,在我的应用程序中有6个按钮,每个都有背景图像,问题是图像在设置为背景时模糊。我试过所有尺寸,但问题保持不变我也尝试将它设置为ImageView,Button和ImageButton。当设置为按钮的背景时,图像变得模糊,ImageButton
如果我设置为背景,应该是图像的大小。
这里是我的XML,这是它的样子.. http://imgur.com/DhHamds
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<ImageButton
android:id="@+id/cstatn"
android:layout_width="0dp"
android:scaleType="fitXY"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageButton
android:id="@+id/cclinic"
android:layout_width="0dp"
android:scaleType="fitXY"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:layout_weight="1" >
<ImageButton
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageButton
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:layout_weight="1" >
<ImageButton
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageButton
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
所以如果我使用9补丁的图像,它不会伸展?根据我的代码应该是图像的大小? – Sunil
9张图片仍然会被拉伸,但它们会根据您的设计进行拉伸。图像的大小取决于图像的内容和按钮的大小,图像应该明显小于按钮。 – Kai
这里在我的上面的代码我没有指定任何宽度和高度的按钮,但是当我试图为一个按钮设置图像时,其拉伸和图像应该在所有类型的设备中看起来不错。 – Sunil