我一直在为我认为简单的事情而苦苦挣扎。我正在使用一个类在图像按钮上设置图像。我想让图像适合屏幕的约束,但是没有拉伸。也就是说,如果它太宽而无法适应屏幕,我想要调整高度以适应屏幕,以便它不会得到拉伸。如果高度过高,我想要降低图像高度,从而缩小宽度。Android:在图像按钮上拉伸/缩放时遇到问题
我见过这个问题,问了几次,我已经尝试了每一点建议,但它对我来说绝对没有什么区别。我认为这可能与使用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文件中的某些垃圾可能是错误的。但是我改变了很多次,并且它有零效果。
任何和所有的建议是大大赞赏。
解决它在这里http://stackoverflow.com/questions/3318629/imagebutton-in-android/19538789#19538789 – HimalayanCoder