【发布时间】:2020-04-17 04:21:26
【问题描述】:
【问题讨论】:
-
您尝试使用
CardView吗? -
这能回答你的问题吗? Android View shadow
标签: android
【问题讨论】:
CardView 吗?
标签: android
使用MaterialCardView 并使用cardElevation
将此添加到 gradle 文件中以使用 material components
implementation 'com.google.android.material:material:1.2.0-alpha03'
style.xml
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
在你的 xml 中
<com.google.android.material.card.MaterialCardView
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:strokeWidth="1dp"
app:strokeColor="@color/stroke_color"
app:cardElevation="10dp"
android:layout_margin="8dp">
//add some view
</com.google.android.material.card.MaterialCardView>
【讨论】:
我认为你可以尝试使用cardView 并添加onclick func 来充当按钮
在cardView内部,你需要自定义TextView、ImageView等你想要的UI布局。
https://guides.codepath.com/android/using-the-cardview
https://material.io/develop/android/components/cards/
按钮阴影,我猜cardView也可以加阴影
【讨论】:
你尝试过:android:elevation="3dp" 在视图 xml 中吗?试试看。
希望对您有所帮助!
【讨论】:
<androidx.cardview.widget.CardView
android:id="@+id/maincard"
android:layout_width="@dimen/_250sdp"
android:layout_height="@dimen/_150sdp"
android:layout_marginStart="@dimen/_5sdp"
android:layout_marginEnd="@dimen/_15sdp"
app:cardCornerRadius="@dimen/_12sdp"
app:cardElevation="@dimen/_10sdp"
app:cardPreventCornerOverlap="false">
【讨论】: