2012-12-23 56 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手動