本文介绍了在卡片视图中使用时,Android中带有圆角的永久性底部工作表会崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在android中创建了一个持久的底部工作表,目的是显示一个包含有关位置的其他信息的ListView.我希望床单上有圆角.对于模态对话框,我有很多结果,但对于持久性却没有.有可能还是应该使用模式版本?

I have created a persistent bottom sheet in android with the intent of displaying a ListView containing additional information about locations. I want the sheet to have rounded corners. I got a ton of results for modal dialog but none for persistent. Is it possible or should I use the modal version?

根据此处答案的建议,我尝试将其包装在卡片视图中,但是当我尝试打开片段时应用程序崩溃.

As suggested in an answer here, I tried wrapping it in a card view but the app crashes when I try to open the fragment.


<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    tools:context=".fragments.MapFragment">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            app:cardCornerRadius="20dp">

            <fragment
                android:id="@+id/autocomplete_fragment"
                android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                tools:layout="@layout/places_autocomplete_item_powered_by_google" />

        </androidx.cardview.widget.CardView>

        <com.google.android.gms.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </RelativeLayout>

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="450dp"
        app:cardCornerRadius="24dp"
        app:cardElevation="8dp"
        app:layout_behavior="@string/bottom_sheet_behavior"
        app:behavior_hideable="true"
        app:behavior_peekHeight="55dp">

        <androidx.core.widget.NestedScrollView
            android:id="@+id/bottom_sheet"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/tvBottomSheet"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/placeholder_text"
                android:textColor="@color/colorCommon_BLACK"
                android:textSize="37sp" />

        </androidx.core.widget.NestedScrollView>

    </androidx.cardview.widget.CardView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

推荐答案

U可以为您的底部工作表背景添加形状

U can add shape for you bottom sheet background background

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">

    <solid android:color="@color/you_color"/>

    <corners
            android:bottomRightRadius="2dp"
            android:bottomLeftRadius="2dp"
            android:topLeftRadius="2dp"
            android:topRightRadius="2dp"/>
</shape>

这篇关于在卡片视图中使用时,Android中带有圆角的永久性底部工作表会崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 07:54