Android Imageview定位覆盖显示而不拉伸

时间:2014-03-20 21:27:49

标签: android android-layout android-imageview

我的水平图像比高大更宽。我希望图像在高度方向上完全填满显示器,我不关心侧面是否被剪掉,因为它是图像的中心,这是很重要的。

当Android设备转向其侧面时,用户应该能够看到更多的图像,因为它是水平显示器上的水平图片。

我一直在使用fill_parent和match_parent来填充内容并通过将它们导出到我的手机来反复测试所有这些内容。它与虚拟设备与我的手机完全不同。

编辑:当设备保持水平和垂直时,主要思想是覆盖整个显示器

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

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:contentDescription="@string/honktext"
        android:onClick="amazinghonks"
        android:scaleType="centerCrop"
        android:src="@drawable/big_clown" />

<TextView
    android:id="@+id/toptext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imageButton1"
    android:layout_alignRight="@+id/imageButton1"
    android:layout_alignTop="@+id/imageButton1"
    android:layout_margin="0dp"
    android:gravity="center"
    android:text="@string/toptext"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#33B5E5" 
    android:background="#CC303030"
    />

</RelativeLayout>

1 个答案:

答案 0 :(得分:2)

你试过这个吗?

android:scaleType="centerCrop"

还是这个?

imageView.setScaleType( ImageView.ScaleType.CENTER_CROP );