设置为 Button,ImageButton 的背景时图像变得模糊

Image gets blur when setting as a background to Button,ImageButton

您好,在我的应用程序中有 6 个按钮,每个按钮都有一个背景图片,问题是设置为时图像变得模糊 background.I 已经尝试了所有尺寸,但问题仍然存在 same.I 也尝试设置它对于 ImageView、Button 和 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>

图片被拉伸是因为您的按钮大小与图片大小不同。要在不拉伸的情况下将图像用作背景,请将图像转换为 9patch 文件。互联网上有很多信息解释它是什么以及如何使用,例如 this one.