2

我有一个带有圆形背景图像 .png 的图像按钮。我在不同分辨率的屏幕上测试它,每个屏幕看起来都不一样。它们中的大多数通过在一维上拉伸来扭曲圆形。

处理这个问题的正确方法是什么?我熟悉最高质量图像所需的 3 个密度级别,但我认为问题在于图像按钮本身或父容器上的布局类型属性。

来自 main.xml 的片段...

<LinearLayout
    android:id="@+id/buttonArea"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:orientation="vertical"
    android:padding="30dp">

    <ImageButton
        android:id="@+id/button1"
        android:background="@drawable/button_inactive"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="center"/>

</LinearLayout>

从 ImageButton 中删除 layout_weight 属性修复了大多数情况,但不是全部。似乎 padding 仍在改变圆的比例。比例类型无效。是不是因为我的图像设置为背景而不是 src?

4

2 回答 2

3

我认为 ImageButton 中的 android:layout_weight="1" 是造成这种情况的原因。无论屏幕尺寸如何,它都会使您的 ImageButton 与屏幕尺寸相同。

尝试删除该属性。如果这不能解决您的问题,请查看android:scaleType属性

<ImageButton
    android:id="@+id/button1"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:layout_gravity="center"
    android:background="@null"
    android:src="@drawable/button_inactive"
    android:scaleType="centerInside"/>
于 2011-12-20T20:31:27.223 回答
2

您可以将 ImageView 的scaleType属性设置为保持图像纵横比的属性。它们的行为都略有不同,因此您必须使用适合您需要的一种(CenterInside 是一个很好的开始)。

如果这不起作用,您始终可以指定图像的设置高度/宽度(例如 layout_width="128dp)。

于 2011-12-20T20:33:29.683 回答