android - 匹配屏幕宽度和图像高度的可点击图像

标签 android android-layout

我正在尝试在 android 中创建一些可点击的图像来填满屏幕的宽度,但可点击表面的高度与图像本身的高度相匹配。

Annoying Extra Space

我有以下代码:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/imageButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/image1"
            android:onClick="onClick2" />

    </RelativeLayout>

到目前为止发布的答案都没有帮助我,FitXY 没有帮助,因为我想保留纵横比。关于图像按钮或更改比例类型的其他答案给我完全相同的问题。

最佳答案

需要的标签是android:adjustViewBounds="true"

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height = "fill_parent" android:layout_width = "fill_parent">
    <ImageView 
        android:layout_width = "wrap_content"
        android:adjustViewBounds="true"
        android:layout_height = "wrap_content" android:id = "@+id/ImageView1"
        android:src = "@drawable/ic_launcher"/>
    <ImageView android:layout_width = "wrap_content"
        android:layout_height = "wrap_content" android:id = "@+id/ImageView2"
        android:src = "@drawable/ic_launcher"
        android:adjustViewBounds="true"
        android:layout_below = "@+id/ImageView1"/>
</RelativeLayout>

关于android - 匹配屏幕宽度和图像高度的可点击图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24428765/

相关文章:

javascript - 在 Android 浏览器中使用 JQuery Mobile 添加点击事件处理程序时出现问题

android - 如何更改自定义警报对话框的背景

android - 相对布局错误。 "is not a sibling"

android - 如何在AlertDialog android中获取RadioGroup的选定索引

android - Arraylist 在 android 中为 null 检查

android - 带有分页架构组件的初始占位符

android - 将参数从 fragment 传递到 View 模型函数

android - 在 Linux 上运行的 Eclipse 不会自动完成 Android XML

java - 有没有一种方法可以同时使用布局宽度和高度的权重

java - 以编程方式在 LinearLayout 中并排设置两个 TextView