有没有办法让CardView只在顶部有一个圆角半径?
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp"
>
Run Code Online (Sandbox Code Playgroud) 我有一个自定义的BttomSheetDialogFragment,我希望在底部视图的顶部有圆角
这是我的自定义类,它让我希望从底部显示我的布局
View mView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.charge_layout, container, false);
initChargeLayoutViews();
return mView;
}
Run Code Online (Sandbox Code Playgroud)
我也有这个xml资源文件作为背景:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners android:topRightRadius="35dp"
android:topLeftRadius="35dp"
/>
<solid android:color="@color/white"/>
<padding android:top="10dp"
android:bottom="10dp"
android:right="16dp"
android:left="16dp"/>
Run Code Online (Sandbox Code Playgroud)
但问题是,当我将此资源文件设置为我的Layout的根元素的背景时,角落仍然没有舍入
我不能使用下面的代码:
this.getDialog().getWindow().setBackgroundDrawableResource(R.drawable.charge_layout_background);
Run Code Online (Sandbox Code Playgroud)
因为它覆盖BottomSheetDialog的默认背景,并且在我的底视图上方不会有任何半透明的灰色
android material-design bottom-sheet material-components material-components-android
我在 android 中创建了一个持久的底部工作表,目的是显示一个包含有关位置的附加信息的 ListView。我希望工作表有圆角。我得到了大量模态对话框的结果,但没有持久性的结果。是否可能或我应该使用模态版本?
正如这里的答案中所建议的那样,我尝试将其包装在卡片视图中,但是当我尝试打开片段时应用程序崩溃了。
<?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>
Run Code Online (Sandbox Code Playgroud) java android material-design bottom-sheet material-components-android