如何在没有图像模糊的情况下拉伸ImageButton?

时间:2014-09-10 14:03:35

标签: android android-layout

我通过“资源选择器”创建了一个新的ImageButton,我最终得到了这段代码:

<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginLeft="14dp"
    android:layout_marginTop="94dp"
    android:src="@drawable/mybutton" />

现在,我想让按钮更大,所以我做了以下更改:

<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginLeft="14dp"
    android:layout_marginTop="94dp"
    android:src="@drawable/aries" />

我还将android:src="@drawable/mybutton"更改为android:background="@drawable/mybutton"以删除图像周围的灰色按钮,然后拉伸图像。

问题:

我的问题是,当拉伸图像时,它仍然使用drawable-mdpi中的文件(应该如此),因此我最终得到了拉伸的低分辨率图像。如果我用高分辨率的drawable-mdpi文件夹更改图像,它看起来很棒,但我很确定这不是最好的解决方案,因为我必须在每个文件夹中放置一个更大分辨率的图像

2 个答案:

答案 0 :(得分:1)

听起来像你需要的是Nine-Patch Drawable

  

NinePatch是一个PNG图像,您可以在其中定义当视图中的内容超出正常图像边界时Android缩放的可伸展区域。 [...]当视图增长以容纳内容时,Nine-Patch图像也会缩放以匹配视图的大小。

答案 1 :(得分:0)

尝试将背景设置为 null

  <ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    android:src="@drawable/ic_launcher" />
相关问题