2012-08-08 64 views
0

我有一個方形的可繪製圖像(drawable-l是1280x1280),我希望它根據設備在哪個方向進行裁剪(橫向,縱向)。我希望圖像始終居中,縮放以填充最大的一面,並將較小的一面裁剪。如何將可繪圖縮放/剪切到最大軸?

這可能嗎?

編輯:

添加到下面普拉莫德Ĵ喬治的回答,如果你拿的ImageView與scaleType:centerCrop,並把它沿側你的主要佈局的FrameLayout內,這將很好地工作!

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

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/background" 
     android:scaleType="centerCrop" 
     android:src="@drawable/background" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/logo" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:contentDescription="@string/logo" 
      android:src="@drawable/logo" /> 

    </LinearLayout> 

</FrameLayout> 

回答