无法通过ConstraintLayout将按钮放置到NestedScrollView的底部

问题描述 投票:1回答:1

我有以下布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/content_ll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/margin_32"
            android:orientation="vertical"
            app:layout_constraintBottom_toTopOf="@id/step7_next_btn"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <androidx.cardview.widget.CardView
                android:id="@+id/online_card_cv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginHorizontal="@dimen/margin_16"
                android:layout_marginTop="25dp"
                android:background="@color/white"
                app:cardCornerRadius="@dimen/margin_8">

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginVertical="@dimen/margin_8">

                    <androidx.appcompat.widget.AppCompatRadioButton
                        android:id="@+id/online_card_rb"
                        android:layout_width="@dimen/margin_22"
                        android:layout_height="@dimen/margin_22"
                        android:layout_marginStart="@dimen/margin_16"
                        app:layout_constraintBottom_toBottomOf="@id/online_card_ll"
                        app:layout_constraintEnd_toStartOf="@id/online_card_ll"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="@id/online_card_ll" />

                    <LinearLayout
                        android:id="@+id/online_card_ll"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="@dimen/margin_16"
                        android:background="@color/white"
                        android:gravity="start"
                        android:orientation="vertical"
                        android:paddingVertical="@dimen/padding_16"
                        app:layout_constraintEnd_toStartOf="@id/cards_iv"
                        app:layout_constraintStart_toEndOf="@id/online_card_rb"
                        app:layout_constraintTop_toTopOf="parent">

                        <TextView
                            android:id="@+id/online_card_tv"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/online_card_title"
                            android:textColor="@color/new_text_color"
                            android:textSize="@dimen/default_text_size_14" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:alpha="0.4"
                            android:text="@string/online_card_now"
                            android:textColor="@color/new_text_color"
                            android:textSize="@dimen/default_text_size_12" />

                    </LinearLayout>

                    <ImageView
                        android:id="@+id/cards_iv"
                        android:layout_width="80dp"
                        android:layout_height="@dimen/margin_20"
                        android:layout_marginEnd="@dimen/margin_16"
                        android:src="@drawable/ic_visa_master"
                        app:layout_constraintBottom_toBottomOf="@id/online_card_ll"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toEndOf="@id/online_card_ll"
                        app:layout_constraintTop_toTopOf="@id/online_card_ll" />

                    <androidx.constraintlayout.widget.ConstraintLayout
                        android:id="@+id/online_card_expanded_info_cl"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:visibility="gone"
                        app:layout_constraintTop_toBottomOf="@id/online_card_ll">

                        <View
                            android:id="@+id/online_card_divider"
                            android:layout_width="match_parent"
                            android:layout_height="1dp"
                            android:layout_marginTop="@dimen/margin_16"
                            android:alpha="0.5"
                            android:background="#000001"
                            app:layout_constraintTop_toTopOf="parent" />

                        <androidx.recyclerview.widget.RecyclerView
                            android:id="@+id/cards_list"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="@dimen/margin_32"
                            app:layout_constraintTop_toBottomOf="@id/online_card_divider" />

                        <View
                            android:id="@+id/cards_list_divider"
                            android:layout_width="match_parent"
                            android:layout_height="1dp"
                            android:layout_marginTop="10dp"
                            android:alpha="0.5"
                            android:background="#000001"
                            app:layout_constraintTop_toBottomOf="@id/cards_list" />

                        <TextView
                            android:id="@+id/read_more_tv"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="@dimen/margin_16"
                            android:layout_marginTop="@dimen/margin_16"
                            android:layout_marginBottom="@dimen/margin_8"
                            android:text="@string/read_more"
                            android:textColor="@color/read_more_color"
                            android:textSize="@dimen/default_text_size_12"
                            android:visibility="visible"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@id/cards_list_divider" />

                        <LinearLayout
                            android:id="@+id/additional_info_ll"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="@dimen/margin_16"
                            android:layout_marginTop="@dimen/margin_16"
                            android:layout_marginBottom="@dimen/margin_8"
                            android:orientation="vertical"
                            android:visibility="gone"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@id/cards_list_divider">

                            <TextView
                                android:id="@+id/online_card_less_info_tv"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="@string/online_card_less_info"
                                android:textColor="@color/read_more_color"
                                android:textSize="@dimen/default_text_size_12" />

                            <TextView
                                android:id="@+id/check_card_type_title_tv"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="@dimen/margin_4"
                                android:text="@string/online_check_card"
                                android:textColor="@color/new_text_color"
                                android:textSize="@dimen/default_text_size_12"
                                android:textStyle="bold" />

                            <TextView
                                android:id="@+id/check_card_type_info_tv"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="@dimen/margin_8"
                                android:layout_marginTop="@dimen/margin_4"
                                android:alpha="0.75"
                                android:text="@string/online_check_card_info"
                                android:textColor="@color/new_text_color"
                                android:textSize="@dimen/default_text_size_12" />

                            <TextView
                                android:id="@+id/online_card_data_title_tv"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="@dimen/margin_4"
                                android:text="@string/online_card_data"
                                android:textColor="@color/new_text_color"
                                android:textSize="@dimen/default_text_size_12"
                                android:textStyle="bold" />

                            <TextView
                                android:id="@+id/online_card_data_info_tv"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="@dimen/margin_8"
                                android:layout_marginTop="@dimen/margin_4"
                                android:alpha="0.75"
                                android:text="@string/online_card_data_info"
                                android:textColor="@color/new_text_color"
                                android:textSize="@dimen/default_text_size_12" />

                            <TextView
                                android:id="@+id/online_card_confirmation_title_tv"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="@dimen/margin_4"
                                android:text="@string/online_card_confirmation"
                                android:textColor="@color/new_text_color"
                                android:textSize="@dimen/default_text_size_12"
                                android:textStyle="bold" />

                            <TextView
                                android:id="@+id/online_card_confirmation_info_tv"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="@dimen/margin_8"
                                android:layout_marginTop="@dimen/margin_4"
                                android:alpha="0.75"
                                android:text="@string/online_card_confirmation_info"
                                android:textColor="@color/new_text_color"
                                android:textSize="@dimen/default_text_size_12" />

                        </LinearLayout>

                    </androidx.constraintlayout.widget.ConstraintLayout>

                </androidx.constraintlayout.widget.ConstraintLayout>

            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:id="@+id/bank_account_cv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginHorizontal="@dimen/margin_16"
                android:layout_marginTop="25dp"
                android:background="@color/white"
                app:cardCornerRadius="@dimen/margin_8">

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginVertical="@dimen/margin_8">

                    <androidx.appcompat.widget.AppCompatRadioButton
                        android:id="@+id/bank_account_rb"
                        android:layout_width="@dimen/margin_22"
                        android:layout_height="@dimen/margin_22"
                        android:layout_marginStart="@dimen/margin_16"
                        app:layout_constraintBottom_toBottomOf="@id/bank_account_tv"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="@id/bank_account_tv" />

                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/bank_account_tv"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginVertical="@dimen/margin_16"
                        android:layout_marginStart="@dimen/margin_14"
                        android:text="@string/title_on_bank"
                        android:textAlignment="textStart"
                        android:textColor="@color/new_text_color"
                        android:textSize="@dimen/default_text_size_14"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toEndOf="@id/bank_account_rb"
                        app:layout_constraintTop_toTopOf="parent" />

                    <androidx.constraintlayout.widget.ConstraintLayout
                        android:id="@+id/bank_account_expanded_cl"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:visibility="gone"
                        app:layout_constraintTop_toBottomOf="@id/bank_account_tv">

                        <View
                            android:id="@+id/bank_account_divider"
                            android:layout_width="match_parent"
                            android:layout_height="1dp"
                            android:layout_marginTop="@dimen/margin_16"
                            android:alpha="0.5"
                            android:background="#000001"
                            app:layout_constraintTop_toTopOf="parent" />

                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/iban_hint_tv"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="@dimen/margin_16"
                            android:layout_marginTop="15dp"
                            android:text="@string/step7_iban_hint"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@id/bank_account_divider" />

                        <com.google.android.material.textfield.TextInputLayout
                            style="@style/LoginTextInputLayoutStyle"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginHorizontal="@dimen/margin_16"
                            android:layout_marginTop="@dimen/margin_2"
                            app:layout_constraintTop_toBottomOf="@id/iban_hint_tv">

                            <androidx.appcompat.widget.AppCompatEditText
                                android:id="@+id/iban_number_et"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content" />

                        </com.google.android.material.textfield.TextInputLayout>

                    </androidx.constraintlayout.widget.ConstraintLayout>

                </androidx.constraintlayout.widget.ConstraintLayout>

            </androidx.cardview.widget.CardView>

        </LinearLayout>

        <androidx.appcompat.widget.AppCompatButton
            android:id="@+id/step7_next_btn"
            android:layout_width="@dimen/width_button_next"
            android:layout_height="@dimen/height_button_next"
            android:layout_marginBottom="@dimen/margin_10"
            android:background="@drawable/rounded_button_next"
            android:text="@string/next"
            android:textColor="@color/button_text_green"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>

我需要将按钮绑在屏幕底部。为此,我为按钮添加了属性app:layout_constraintBottom_toBottomOf="parent"。但是,当我运行该应用程序时,我的屏幕将以这种方式显示:

enter image description here

所以,为什么它会这样,我应该添加些什么以将其绑定到屏幕底部。感谢您的帮助,谢谢!

android android-constraintlayout
1个回答
1
投票

android:fillViewport="true"中添加NestedScrollView

<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
© www.soinside.com 2019 - 2024. All rights reserved.