【问题标题】:Android Imageview positioning to cover the display without stretchingAndroid Imageview 定位覆盖显示不拉伸
【发布时间】:2014-03-21 05:53:01
【问题描述】:

我有一个比高更宽的水平图像。我希望图像在高度上完全填满显示器,我不在乎两侧是否被剪掉,因为它是图像的中心,很重要。

当 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>

【问题讨论】:

    标签: android android-layout android-imageview


    【解决方案1】:

    你试过了吗?

    android:scaleType="centerCrop"
    

    还是这个?

    imageView.setScaleType( ImageView.ScaleType.CENTER_CROP );
    

    【讨论】:

    • 是的,使用 centerCrop 作为比例类型。这是正确答案:)
    • 我要去掉 layout_width 和 height 吗?或者只是添加它。让我尝试导出到我的关系。
    • 成功了!但是,我想我看到了一个点击监听器,它给了我一个小的 5dp 边距,我似乎无法摆脱。
    • android:padding="0dp" 添加到您的 ImageButton
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多