自动设置ImageView和Button的高度

时间:2018-06-30 01:13:07

标签: android android-imageview

我正在尝试设置图像视图的高度和为不同设备自动调整大小的按钮。无论图像的高度是多少,我都希望在imageview下方显示按钮。

我正在尝试此代码:

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

    <Button
        android:id="@+id/send_btn"
        android:layout_bellow="imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

预先感谢

1 个答案:

答案 0 :(得分:1)

我想,您正在使用LinerLayout和android:orientantion =“ vertical”。 我将使用layout_weight属性,如下所示:

<ImageView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1" />

<Button
    android:id="@+id/send_btn"
    android:layout_bellow="imageView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

它将自动用图像视图填充所有上部。

通过在ImageView中使用layout_weight =“ 1”和layout_height =“ wrap_content”,您可以告诉Android ImageView是“重要的”并且必须填充所有剩余空间。