Как выровнять линейный макет объявления внизу в представлении прокрутки?

#android #android-studio #android-layout #scrollview #android-linearlayout

Вопрос:

Пожалуйста, ознакомьтесь с моим кодом. Я хочу установить последний линейный макет в нижней части страницы. Если я через него выйду за пределы Scrollview, это не сработает. Может ли кто-нибудь помочь мне решить эту проблему, пожалуйста.. Я прикрепил код. Я пробую это с другой комбинацией, но это не сработало. Заранее спасибо.

 xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fillViewport="true"
android:paddingTop="65dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/backgroundmain"
tools:context=".TeamInfoAll">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp">

        <androidx.cardview.widget.CardView

            android:id="@ id/topcard"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
            android:layout_marginLeft="14dp"
            android:layout_marginRight="14dp"
            android:layout_marginBottom="14dp"
            app:cardBackgroundColor="#FAFAFA"
            app:cardCornerRadius="12dp"
            app:cardElevation="8dp"
            tools:targetApi="lollipop">


            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/aboutbackground"
                android:textAlignment="center"/>

        </androidx.cardview.widget.CardView>

    </LinearLayout>


    <GridLayout
        android:id="@ id/mainGrid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:alignmentMode="alignMargins"
        android:columnOrderPreserved="false"
        android:padding="10dp"
        android:columnCount="1"
        android:rowCount="6">

        <!--Row 1-->

        <androidx.cardview.widget.CardView

            android:id="@ id/cardView1"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            app:cardBackgroundColor="#4CAF50"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="14dp"
            android:layout_marginLeft="14dp"
            android:layout_marginRight="14dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="12dp"
            tools:targetApi="lollipop">

            <TextView
                android:id="@ id/cardView1Text"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="@string/Team1"
                android:gravity="center_vertical"
                android:textAlignment="center"
                android:textColor="#FFFFFF"
                android:textSize="25sp"
                tools:ignore="RtlCompat" />
        </androidx.cardview.widget.CardView>

        <!--Row 2-->

        <androidx.cardview.widget.CardView

            android:id="@ id/cardView2"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            app:cardBackgroundColor="#F44336"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="14dp"
            android:layout_marginLeft="14dp"
            android:layout_marginRight="14dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="12dp"
            tools:targetApi="lollipop">

            <TextView
                android:id="@ id/cardView2Text"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="@string/Team2"
                android:gravity="center_vertical"
                android:textAlignment="center"
                android:textColor="#FFFFFF"
                android:textSize="25sp"
                tools:ignore="RtlCompat" />
        </androidx.cardview.widget.CardView>

        <!--Row 3-->

        <androidx.cardview.widget.CardView

            android:id="@ id/cardView3"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            app:cardBackgroundColor="#2196F3"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="14dp"
            android:layout_marginLeft="14dp"
            android:layout_marginRight="14dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="12dp"
            tools:targetApi="lollipop">

            <TextView
                android:id="@ id/cardView3Text"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="@string/Team3"
                android:gravity="center_vertical"
                android:textAlignment="center"
                android:textColor="#FFFFFF"
                android:textSize="22sp"
                tools:ignore="RtlCompat" />
        </androidx.cardview.widget.CardView>



    </GridLayout>



    <LinearLayout

        android:id="@ id/banner_container1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="32dp"
        android:gravity="bottom"
        android:orientation="vertical"
        tools:ignore="ObsoleteLayoutParam" />

</LinearLayout>
 

Ответ №1:

Попробуйте Это

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

    <ScrollView
        android:id="@ id/scrollView2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@drawable/backgroundmain"
        android:fillViewport="true"
        android:orientation="vertical"
        android:paddingTop="65dp"
        app:layout_constraintBottom_toTopOf="@ id/banner_container1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:context=".TeamInfoAll">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="10dp">

                <androidx.cardview.widget.CardView

                    android:id="@ id/topcard"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_rowWeight="1"
                    android:layout_columnWeight="1"
                    android:layout_marginLeft="14dp"
                    android:layout_marginRight="14dp"
                    android:layout_marginBottom="14dp"
                    app:cardBackgroundColor="#FAFAFA"
                    app:cardCornerRadius="12dp"
                    app:cardElevation="8dp"
                    tools:targetApi="lollipop">


                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/aboutbackground"
                        android:textAlignment="center" />

                </androidx.cardview.widget.CardView>

            </LinearLayout>


            <GridLayout
                android:id="@ id/mainGrid"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:alignmentMode="alignMargins"
                android:columnCount="1"
                android:columnOrderPreserved="false"
                android:padding="10dp"
                android:rowCount="6">

                <!--Row 1-->

                <androidx.cardview.widget.CardView

                    android:id="@ id/cardView1"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:layout_rowWeight="1"
                    android:layout_columnWeight="1"
                    android:layout_marginLeft="14dp"
                    android:layout_marginRight="14dp"
                    android:layout_marginBottom="14dp"
                    app:cardBackgroundColor="#4CAF50"
                    app:cardCornerRadius="12dp"
                    app:cardElevation="8dp"
                    tools:targetApi="lollipop">

                    <TextView
                        android:id="@ id/cardView1Text"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center_vertical"
                        android:text="@string/Team1"
                        android:textAlignment="center"
                        android:textColor="#FFFFFF"
                        android:textSize="25sp"
                        tools:ignore="RtlCompat" />
                </androidx.cardview.widget.CardView>

                <!--Row 2-->

                <androidx.cardview.widget.CardView

                    android:id="@ id/cardView2"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:layout_rowWeight="1"
                    android:layout_columnWeight="1"
                    android:layout_marginLeft="14dp"
                    android:layout_marginRight="14dp"
                    android:layout_marginBottom="14dp"
                    app:cardBackgroundColor="#F44336"
                    app:cardCornerRadius="12dp"
                    app:cardElevation="8dp"
                    tools:targetApi="lollipop">

                    <TextView
                        android:id="@ id/cardView2Text"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center_vertical"
                        android:text="@string/Team2"
                        android:textAlignment="center"
                        android:textColor="#FFFFFF"
                        android:textSize="25sp"
                        tools:ignore="RtlCompat" />
                </androidx.cardview.widget.CardView>

                <!--Row 3-->

                <androidx.cardview.widget.CardView

                    android:id="@ id/cardView3"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:layout_rowWeight="1"
                    android:layout_columnWeight="1"
                    android:layout_marginLeft="14dp"
                    android:layout_marginRight="14dp"
                    android:layout_marginBottom="14dp"
                    app:cardBackgroundColor="#2196F3"
                    app:cardCornerRadius="12dp"
                    app:cardElevation="8dp"
                    tools:targetApi="lollipop">

                    <TextView
                        android:id="@ id/cardView3Text"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center_vertical"
                        android:text="@string/Team3"
                        android:textAlignment="center"
                        android:textColor="#FFFFFF"
                        android:textSize="22sp"
                        tools:ignore="RtlCompat" />
                </androidx.cardview.widget.CardView>


            </GridLayout>


        </LinearLayout>
    </ScrollView>

    <LinearLayout

        android:id="@ id/banner_container1"
        android:layout_width="0dp"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:gravity="bottom"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        tools:ignore="ObsoleteLayoutParam" />
</androidx.constraintlayout.widget.ConstraintLayout>
 

Вы можете отрегулировать высоту нижней компоновки в соответствии с вашими требованиями.

Комментарии:

1. спасибо, пожалуйста, поддержите нас, чтобы мы были мотивированы