2012-07-08 174 views
0

我想要调整图像的大小以适应屏幕,以填充整个宽度。高度应该设置为高宽比。 例如,图像尺寸是widthxheight 10x5,手机宽度是400。图像应该以200x400显示。Android布局,缩放到屏幕分辨率的宽度

我有一些设置发挥各地 机器人:scaleType =“中心”应根据文档正确的设置,但似乎没有任何效果, 机器人:scaleType =“centerCrop”适合HIGHT,使宽度大于大屏幕。

我的继承人布局:

<?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> 

非常感谢

回答

1

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

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

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

+0

没有工作,居中图像,但使用图像的宽度和高度。也试过android:layout_width =“match_parent” android:layout_height =“match_parent” – user1324936 2012-07-09 17:35:33