2012-08-08 81 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> 

回答