2012-12-23 54 views
0

我在尝试将一个方形图像(即大约315dp x 315dp)缩放到应填充宽度并具有大约200dp高度的图像时遇到了一些麻烦。如何正确缩放一个矩形imageview到一个矩形imageview?

基本上我试图做的是只是适当地保留图像的长宽比,当它被缩放到一个更长的形状。有任何想法吗?以下是我已经试过:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" > 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" 
     android:adjustViewBounds="true" 
     android:scaleType="centerCrop" /> 

</LinearLayout> 

回答

0
It should be like that 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" > 
    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="200dp"> 
    <ImageView 
     android:id="@+id/image" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" 
     android:adjustViewBounds="true" 
     android:scaleType="fitXY" /> 
    </FrameLayout> 

</LinearLayout> 

的FrameLayout里就是解决你的形象大小,如果你需要你更多的帮助应详阅Android UI手动