如何防止我的位图从如果视图或按钮使用“FILL_PARENT”或使用“重量”被拉伸在ImageView的或ImageButton的自动缩放?

这将是有用的,例如,在其中该按钮被相等地间隔在屏幕的顶部创建一个4按钮工具栏,但按键内部的图像继续得到streched即使我使用scaleType =“中心”,应避免根据文档的缩放,但事实并非如此。

任何了解表示赞赏!

谢谢,

有帮助吗?

解决方案

我发现,采用了android时:后台自动缩放您使用那里的视图大小的图像

我尝试使用机器人:SRC把图像中的视图。图像没有形成规模,但我不能让图像居中相对于视图的大小。

所以我试图使整个按钮它自己的相对布局,这是我用什么:

<RelativeLayout android:id="@+id/RelativeLayout01" 
                android:layout_height="fill_parent" 
                android:layout_width="fill_parent">
                <ImageButton android:id="@+id/ImageButton01"    
                             android:layout_height="fill_parent"
                             android:layout_width="fill_parent"></ImageButton>
                <ImageView android:id="@+id/ImageView01"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content" 
                           android:background="@drawable/cardback1" 
                           android:layout_centerInParent="true"></ImageView>
</RelativeLayout>

在ImageButton的是在背景中和将总是大小作为布局相同。 该ImageView的但将永远留在中心的RelativeLayout的,并不会规模。 通过这种方式,RelativeLayout的自身成长和移动和按钮的排头的图像将始终保持相同的大小,但按钮将增长。如果布局变得比图像本身更小的图像将然而收缩。

我想这就是你要找的人。有可能是一个更好的办法来做到这一点,但是这是所有我能想出现在。

其他提示

只需修改您的可拉伸,施加较大的透明背景。说我在华电国际绘制是41 * 48像素的icon.png。我创建了一个新的图像60 * 60像素透明背景,复制粘贴以前的icon.png,并在相同的名称保存。这样,你不需要触摸你的布局。

然后可以检查按钮区域较大如果应用的非透明机器人:背景

<ImageButton android:id="@+id/widget_open"
android:src="@drawable/icon_widget_arrow_up"
android:background="#ff777777"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageButton>

应用了以前和现在绘制为的android:SRC ,你应该清楚地看到ImageButton的区域。

顺便说,我运行在兼容模式的应用程序。

如果对图像进行缩放,确保不会在兼容模式运行应用程式(例如,如果你指定Android 1.5 / 1.6无支持多种密度,并且在运行在Android 2.0的应用程序。)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top