【问题标题】:Equally distanced buttons appear blurry等距的按钮显得模糊
【发布时间】:2012-01-09 02:27:39
【问题描述】:

我在一个等距放置的线性布局中有 4 个 ImageButton。现在我为所有 4 个 ImageButtons 使用一个背景,资源大小为 36x36。

ImageButton 显得拉伸和模糊。我做错了什么?

<LinearLayout
        android:id="@+id/layout_buttons"

        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_weight="1"
        android:gravity="center"
        android:background="@drawable/bg_tabbar_tile"
        >

        <ImageButton
            android:id="@+id/play"
            android:layout_width="0px"
            android:layout_height="wrap_content"
            android:background="@drawable/play"
            android:layout_weight="1" 
            />
        <ImageButton
            android:id="@+id/play1"
            android:layout_width="0px"
            android:layout_height="wrap_content"
            android:background="@drawable/play"
            android:layout_weight="1"
            />

        <ImageButton
            android:id="@+id/play2"
            android:layout_width="0px"
            android:layout_height="wrap_content"
            android:background="@drawable/play"
            android:layout_weight="1"
            />

        <ImageButton
            android:id="@+id/play3"
            android:layout_width="0px"
            android:layout_height="wrap_content"
            android:background="@drawable/play"
            android:layout_weight="1"
            />
        </LinearLayout>

提前致谢

【问题讨论】:

    标签: android layout imagebutton


    【解决方案1】:

    默认情况下,背景可绘制对象被拉伸到包含视图的大小。您可以通过使用 BitmapDrawable 来避免这种情况。将其放入 res/drawable 的新 XML 文件中:

    <?xml version="1.0" encoding="utf-8"?>
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
          android:src="@drawable/play"
          android:gravity="center" />
    

    然后在您的图像按钮中使用这个新的可绘制对象而不是 @drawable/play

    【讨论】:

    • 我为 xml 文件命名是否重要?
    • 完美答案...这就是我所做的...在可绘制文件夹中创建的 button.xml 具有 schemas.android.com/apk/res/android"> 和布局而不是做@drawable/play 做@drawable/button
    • @Abid - 你可以给它起任何名字。抱歉,我遗漏了 xmlns 属性。我将编辑我的答案以包含它,以防其他人试图模仿。
    猜你喜欢
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 2012-05-29
    相关资源
    最近更新 更多