我一直在苦恼一个看起来很简单的问题。我正在使用一个类来设置图像按钮上的图片。我希望图片适应屏幕的大小限制,但是不要拉伸。也就是说,如果它太宽而无法适应屏幕,我希望高度被缩放以容纳它,这样它就不会被拉伸了。而如果高度过高,我希望图像高度减小,同时缩小宽度。
我看到有这个问题不止一次地被问到,我尝试了所有建议,但对我来说没有任何影响。我认为这可能与使用ImageButton而不是ImageView有关?
以下是一些相关的代码片段(破碎得很厉害)...
在我的类中:
ImageView img = (ImageButton) dialog.findViewById(R.id.fullsizeimage);
img.setScaleType(ImageView.ScaleType.CENTER_INSIDE); //Changing ScaleType here has no effect
img.setImageBitmap(useThisBitmap);
以下是XML布局内容...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageButton
android:id="@+id/fullsizeimage"
android:background="@null"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
/>
</RelativeLayout>
XML文件中的某些内容可能是错误的。但我已经改了很多次,却没有任何效果。
非常感谢任何建议。