我有两个底层工作表对话框片段布局,我已将其包含在一个名为 "Downtown Sheet Dialog Fragment "的文件中。CoordinatorLayout
. 该 CoordinatorLayout
拥有 RecyclerView
其项目在被点击后显示一个底层工作表对话框片段。第一个底单对话片段用于更新回收商视图中的项目,第二个底单对话片段用于执行项目的支付。第二个Bottom Sheet对话片段用于执行项目的支付。我遇到的问题是,当我显示第二个底层表进行支付时,错误地点击了项目,第一个底层表在第二个底层表下面。有什么办法可以在显示第二张底单时,将第一张底单对话框设置为禁用或像按钮一样设置为不可见。
这是我的XML
<androidx.coordinatorlayout.widget.CoordinatorLayout 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=".Activities.CartActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/cart_tool_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</com.google.android.material.appbar.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhiteShade">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/cart_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorWhiteDarker"
android:padding="5dp"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="5dp"
android:layout_margin="2dp"
android:padding="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<TextView
android:id="@+id/tv_sub_total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sub_total"
android:textSize="20sp"
style="@style/TextAppearance.AppCompat.Large"/>
<TextView
android:id="@+id/sub_total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sub_total"
style="@style/TextAppearance.AppCompat.Body1"
android:textStyle="bold"
android:layout_alignParentEnd="true"
android:textSize="17sp"
/>
<View
android:id="@+id/view"
android:layout_centerHorizontal="true"
android:layout_width="350dp"
android:layout_height="1dp"
android:background="@color/colorBlack20"
android:layout_margin="2dp"
android:layout_below="@id/sub_total"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/view"
android:layout_margin="2dp"
android:padding="2dp"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="@+id/btn_post_payment"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:drawableStart="@drawable/pay_icon"
android:text="@string/pay"
android:background="@drawable/ripple"
android:layout_marginStart="2dp"
android:layout_marginEnd="2dp"
android:textColor="@android:color/white"
android:padding="5dp"
style="?attr/borderlessButtonStyle"
android:textAllCaps="false"/>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<!-- Always include layout below all the other layouts -->
<include layout="@layout/layout_cart_bottom_sheet"/>
<!-- Always include layout below all the other layouts -->
<include layout="@layout/layout_post_payment"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
另一个我喜欢的实现是,如果第一个对话框可以检查第二个对话框是否已经显示,并防止它再次显示。
你可以设置可见性为。
<include layout="@layout/layout_cart_bottom_sheet" visibility="gone"/>
或者给布局设置一个ID
<include android:id="@+id/cart_bottomsheet" layout="@layout/layout_cart_bottom_sheet">
并使用 findViewById
和 setVisibility
.