Android布局,缩放宽度到屏幕分辨率

时间:2012-07-08 12:23:21

标签: android layout

我想调整图像大小以适应屏幕填充整个宽度。高度应设置为宽高比。 例如,图像尺寸为widthxheight 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>

非常感谢

2 个答案:

答案 0 :(得分:1)

您应该尝试android:scaleType="centerInside"

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

  

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

答案 1 :(得分:0)