保持按钮对话框的底部
我有一个像设计1 这样的布局,我想总是将取消按钮与对话框的底部保持一致。 RecyClerview1&由于显示内容,RecyClerview2具有不同的高度。如果RecyClerview1和RecyClerview内容都很小,并且能够在屏幕中显示不滚动,则应该像 Design 2 。如果循环系统超过高度对话框,则应将设备高度放在对话框的底部,例如 Design 3 。
当前代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="text1"
android:textSize="10sp" />
<TextView
android:id="@+id/textview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@id/textview1"
android:text="text2"
android:textSize="10sp" />
<androidx.core.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_below="@id/textview2"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayoutContainer1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayoutContainer2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/scrollView"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:gravity="right">
<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"/>
</LinearLayout>
</RelativeLayout>
I've a layout like design 1 and I want to align cancel button to bottom of the dialog always. recyclerview1 & recyclerview2 have different heights due to display content. if the both recyclerview1 and recyclerview content are small and able to display within screen without scroll it should be like design 2 . If the recyclerviews exceeded the heights dialog should take the device height and align cancel button to bottom of the dialog like design 3.
Current output and final output
Current code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="text1"
android:textSize="10sp" />
<TextView
android:id="@+id/textview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@id/textview1"
android:text="text2"
android:textSize="10sp" />
<androidx.core.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_below="@id/textview2"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayoutContainer1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayoutContainer2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/scrollView"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:gravity="right">
<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"/>
</LinearLayout>
</RelativeLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将不得不
使用重力底部创建一个自定义对话框()在OnViewCreated()中膨胀一个layout_bottom_button,因此膨胀的布局将始终保持在底部,
请记住,recyClerview应该具有与Layout_bottom_bottom_bottom_button Layut高度相同的底部余量。
You will have to create a custom dialog
inside onViewCreated() inflate a layout_bottom_button using gravity bottom, so inflated layout will always be at bottom
keep in mind that recyclerView should have bottom margin same as layout_bottom_button layout height, so that recyclerView does not hide below button.