如何将特定布局与底部对齐并修复imageview的大小以覆盖剩余空间?

时间:2017-06-05 12:18:07

标签: android android-linearlayout android-relativelayout

我有一个imageview&相对布局,其中包含两个按钮的布局应与底部对齐,圆形图像应拉伸以占用剩余空间。我尝试了其他答案,但无法做到。我有下面的代码和图片。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cardview_light_background"
android:clickable="true">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <include layout="@layout/toolbar_child_with_progress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/toolbar_child"/>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar_child">
        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >
                <ImageView
                    android:id="@+id/iv_SavedInvoice"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:src="@drawable/service_app_logo"
                    android:scaleType="fitStart"
                    android:adjustViewBounds="true"
                    android:layout_centerHorizontal="true"
                    />

                <LinearLayout
                    android:id="@+id/ll_inner"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_below="@+id/iv_SavedInvoice"
                    android:layout_alignParentBottom="true"
                    >
                    <Button
                        style="@style/PrimaryButton"
                        android:layout_marginTop="20dp"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/form_proof_replace_invoice"
                        android:id="@+id/button_ReplaceInvoice" />
                    <Button
                        style="@style/NoBorderButton"
                        android:layout_marginTop="20dp"
                        android:layout_marginBottom="20dp"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/form_proof_next"
                        android:id="@+id/button_SavedProofNext" />
                </LinearLayout>
            </RelativeLayout>
    </ScrollView>
</RelativeLayout>

Align_Parent_Bottom

2 个答案:

答案 0 :(得分:1)

您应该设置 layout_height match_parent 而不是 wrap_content

<LinearLayout
                    android:id="@+id/ll_inner"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:layout_below="@+id/iv_SavedInvoice"
                    android:layout_alignParentBottom="true"
                    >

其次,在 ScrollView 部分添加 android:fillViewport="true"

答案 1 :(得分:1)

我不知道您使用ScrollView和其他嵌套布局的原因。您可以使用布局权重属性简单地实现所需的UI。您检查此代码并根据需要进行更改。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cardview_light_background"
android:clickable="true"
android:orientation="vertical">

<include
    android:id="@+id/toolbar_child"
    layout="@layout/toolbar_child_with_progress"
    android:layout_width="match_parent"
    android:layout_height="50dp" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">

    <ImageView
        android:id="@+id/iv_SavedInvoice"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="true"
        android:scaleType="fitStart"
        android:src="@mipmap/ic_launcher" />


</RelativeLayout>

<LinearLayout
    android:id="@+id/ll_inner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/iv_SavedInvoice"
    android:orientation="vertical">

    <Button
        android:id="@+id/button_ReplaceInvoice"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="form_proof_replace_invoice" />

    <Button
        android:id="@+id/button_SavedProofNext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="form_proof_next" />
</LinearLayout>

</LinearLayout>