0

我想调整图像的大小以适应它填充整个宽度的屏幕。高度应设置为纵横比。例如,图像尺寸为宽x高 10x5,手机为 400 宽。图像应以 200x400 显示。

我玩了一些设置 android:scaleType="center" 根据文档应该是正确的设置,但似乎没有效果, android:scaleType="centerCrop" 适合高度并使宽度大于屏幕。

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageViewFrage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:padding="1dp"
        android:scaleType="centerCrop"
        android:src="@drawable/bg_striped_img" />
</LinearLayout>

</LinearLayout>

多谢

4

2 回答 2

1

你应该试试android:scaleType="centerInside"

根据文档(http://developer.android.com/reference/android/widget/ImageView.ScaleType.html):

均匀缩放图像(保持图像的纵横比),使图像的两个尺寸(宽度和高度)都等于或小于视图的相应尺寸(减去填充)。然后图像在视图中居中。

于 2012-07-08T12:36:50.563 回答
0

好的不会工作。太糟糕了。找到了这个sol

http://argillander.wordpress.com/2011/11/24/scale-image-into-imageview-then-resize-imageview-to-match-the-image/

于 2012-07-09T18:30:52.067 回答