如何解决带有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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。