2015-08-03 71 views
0

我想弄清楚如何在Android ImageView中加载一幅肖像或风景图像,而不需要将图像拉伸到全屏。调整Android ImageView的风景和肖像

例如,以纵向查看时的横向图像不应伸展到全屏,而是以上部和下部的黑色条纹为中心以补偿空白空间。

有什么想法?

感谢

+0

使用布局端口和布局,土地资源文件夹,文件夹内。 –

回答

1

设置的ImageView的高度和宽度match_parent,whitout使用任何scaleType

<ImageView 
     android:id="@+id/img_1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 

它会自动适合人像和风景

1

为了达到你需要的效果使用scaleType属性和黑色背景。

<ImageView 
    android:id="@+id/your_image" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scaleType="centerInside" 
    android:background="#000000"/> 

然后,你需要设置图像资源。

通过XML:

android:src="@drawable/your_image_drawable" 

通过代码:

yourImageViewReference.setImageResource(R.drawable.your_image_drawable);