如何在模糊背景的同时将网格视图显示为对话
How show cardview as a dilouge while bluring the background
我有一个带有 2 个单选按钮的卡片视图,我想将其显示为对话
我想实现多项目标
- 将卡片视图显示为对话
- 显示对话框时模糊背景布局
- 我有 2 个单选按钮(只有一个可以选择)我希望在选择其中一个之后对话会消失但不会立即消失至少应该有一个短暂的延迟以便用户可以看到单选按钮的选择
Note:- If you want more references of the code please tell me I will
update the question as you can find I dint include the fragment_home
java file so the question doesn't get long and confusing
布局如下
sort_image.xml
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:backgroundTint="@color/grey"
app:cardCornerRadius="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/sort_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginTop="5dp"
android:fontFamily="@font/roboto"
android:text="Sort by"
android:textAlignment="center"
android:textColor="@color/lite_grey"
android:textSize="25sp" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/divider_line_sort_by"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/sort_textView"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="10dp"
android:backgroundTint="@color/lite_grey"
app:cardCornerRadius="50dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:id="@+id/latest_sort_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:fontFamily="@font/roboto"
android:text="Latest"
android:textAlignment="center"
android:textColor="@color/lite_grey"
android:textSize="25sp" />
<TextView
android:id="@+id/most_popular_sort_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/latest_sort_textView"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:layout_marginStart="30dp"
android:layout_marginTop="25sp"
android:fontFamily="@font/roboto"
android:text="Most Popular"
android:textAlignment="center"
android:textColor="@color/lite_grey"
android:textSize="25sp" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true">
<RadioButton
android:id="@+id/latest_sort_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25sp" />
<RadioButton
android:id="@+id/most_popular_sort_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</RadioGroup>
</RelativeLayout>
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
fragment_home.xml // 此布局包含我想要的文本,按下时我会打开对话框,这也是我想要的 fragment/layout显示对话时模糊
Note:- only included the necessary code of this layout
<com.google.android.material.card.MaterialCardView
android:id="@+id/sort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:layout_toStartOf="@id/divider_line"
android:backgroundTint="@color/black"
android:elevation="6dp"
android:paddingBottom="10dp"
android:textAlignment="center"
app:cardCornerRadius="10dp">
<TextView
android:id="@+id/sort_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="5dp"
android:fontFamily="@font/roboto"
android:text="@string/sort"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="17sp"
android:textStyle="bold" />
</com.google.android.material.card.MaterialCardView>
我认为您需要使用对话框片段。您可以在官方文档中阅读更多相关信息 https://developer.android.com/guide/fragments/dialogs
我有一个带有 2 个单选按钮的卡片视图,我想将其显示为对话
我想实现多项目标
- 将卡片视图显示为对话
- 显示对话框时模糊背景布局
- 我有 2 个单选按钮(只有一个可以选择)我希望在选择其中一个之后对话会消失但不会立即消失至少应该有一个短暂的延迟以便用户可以看到单选按钮的选择
Note:- If you want more references of the code please tell me I will update the question as you can find I dint include the fragment_home java file so the question doesn't get long and confusing
布局如下
sort_image.xml
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:backgroundTint="@color/grey"
app:cardCornerRadius="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/sort_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginTop="5dp"
android:fontFamily="@font/roboto"
android:text="Sort by"
android:textAlignment="center"
android:textColor="@color/lite_grey"
android:textSize="25sp" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/divider_line_sort_by"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/sort_textView"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="10dp"
android:backgroundTint="@color/lite_grey"
app:cardCornerRadius="50dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:id="@+id/latest_sort_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:fontFamily="@font/roboto"
android:text="Latest"
android:textAlignment="center"
android:textColor="@color/lite_grey"
android:textSize="25sp" />
<TextView
android:id="@+id/most_popular_sort_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/latest_sort_textView"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:layout_marginStart="30dp"
android:layout_marginTop="25sp"
android:fontFamily="@font/roboto"
android:text="Most Popular"
android:textAlignment="center"
android:textColor="@color/lite_grey"
android:textSize="25sp" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true">
<RadioButton
android:id="@+id/latest_sort_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25sp" />
<RadioButton
android:id="@+id/most_popular_sort_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</RadioGroup>
</RelativeLayout>
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
fragment_home.xml // 此布局包含我想要的文本,按下时我会打开对话框,这也是我想要的 fragment/layout显示对话时模糊
Note:- only included the necessary code of this layout
<com.google.android.material.card.MaterialCardView
android:id="@+id/sort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:layout_toStartOf="@id/divider_line"
android:backgroundTint="@color/black"
android:elevation="6dp"
android:paddingBottom="10dp"
android:textAlignment="center"
app:cardCornerRadius="10dp">
<TextView
android:id="@+id/sort_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="5dp"
android:fontFamily="@font/roboto"
android:text="@string/sort"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="17sp"
android:textStyle="bold" />
</com.google.android.material.card.MaterialCardView>
我认为您需要使用对话框片段。您可以在官方文档中阅读更多相关信息 https://developer.android.com/guide/fragments/dialogs