最近我想构建这样的东西
但是不幸的是,我无法在圆角处使其阴影,而且这里似乎还有多余的背景(即使我将android:background设置为透明)
有什么主意吗?
主要布局
.....
</androidx.cardview.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom">
<include layout="@layout/main_menu_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:id="@+id/bottom_menu"/>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
....
包含的布局
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@drawable/top_shadow_gradient" />
<LinearLayout
android:layout_width="match_parent"
android:background="@drawable/layout_bg_rounded_corner"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:id="@+id/home"
android:background="?attr/selectableItemBackground"
android:orientation="vertical">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="@dimen/one_x"
android:src="@drawable/ic_icon_homehdpi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/one_x"
android:textColor="@color/colorPrimary"
android:text="@string/home_menu_home"/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/one_x"
android:layout_marginTop="@dimen/one_x"
android:id="@+id/home_selected"
android:background="@drawable/rounded_bottom_menu_selected"/>
</LinearLayout>
.........
bg圆角
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="1dp" android:color="#B1BCBE" />
<corners android:topLeftRadius="20dp" android:topRightRadius="20dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
事实证明
Ps。 我尝试过不使用包含,它也不起作用。
答案 0 :(得分:0)
请改用CardView
。
创建形状:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white" />
<corners android:topLeftRadius="18dp" android:topRightRadius="18dp" />
</shape>
并将其设置为您的CardView
,如下所示:
cardView.setBackgroundResource(R.drawable.your_shape);
或者(尚未测试)
android:background="@drawable/your_shape";