带有Viewpager的布局底部的静态按钮

问题描述

我正在制作一个项目,在该项目中我使用了片段和viewpager,但在主屏幕上我想要底部固定的选项卡,在底部我需要2个按钮。 我想在viewpager下面的屏幕末尾添加2个按钮,我该怎么做? 我做了几件事,但是我没有得到想要的结果

我想问的另一件事,是否应该更改主布局? 我尝试过但没有得到结果

这是我的代码帮我...

<LinearLayout 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"
    tools:context=".AfterSendViewPager"
    android:orientation="vertical">
    
    
    <include
        layout="@layout/toolbar_layout"/>

    <com.google.android.material.tabs.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tablayout"
        android:background="#494545"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ShapeAppearance.MaterialComponents.MediumComponent" />
    
    
    <androidx.viewpager.widget.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/viewpager"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:id="@+id/bottomupdatelayout"
        android:orientation="horizontal"

        >

        <com.google.android.material.button.MaterialButton
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:id="@+id/selectedButtonBottom"
            android:theme="@style/Widget.MaterialComponents.Button.OutlinedButton"
            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
            android:textColor="#2C771B"
            android:layout_margin="5dp"
            android:text="Selected"
            android:layout_weight="1"
            />

        <com.google.android.material.button.MaterialButton
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:id="@+id/sendButtonBottom"
            android:theme="@style/Widget.MaterialComponents.Button.OutlinedButton"
            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
            android:textColor="#2C771B"
            android:layout_margin="5dp"
            android:text="Send"
            android:layout_weight="1"
            />


    </LinearLayout>




</LinearLayout>

预先感谢☺

解决方法

使用由LinearLayout插入的ConstraintLayout使用此代码

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">


    <include
        layout="@layout/header_layout"/>

    <com.google.android.material.tabs.TabLayout
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tablayout"
        android:background="#494545"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ShapeAppearance.MaterialComponents.MediumComponent" />

    <androidx.viewpager.widget.ViewPager
        app:layout_constraintTop_toBottomOf="@id/tablayout"
        app:layout_constraintBottom_toTopOf="@id/bottomupdatelayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#00BCD4"
        android:id="@+id/viewpager"/>

    <LinearLayout
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bottomupdatelayout"
        android:orientation="horizontal">

        <com.google.android.material.button.MaterialButton
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:id="@+id/selectedButtonBottom"
            android:textColor="#2C771B"
            android:layout_margin="5dp"
            android:text="Selected"
            android:layout_weight="1"
            />

        <com.google.android.material.button.MaterialButton
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:id="@+id/sendButtonBottom"
            android:textColor="#2C771B"
            android:layout_margin="5dp"
            android:text="Send"
            android:layout_weight="1"/>


    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>