how to create this type of layout in android look like image
Asked
Active
Viewed 3,598 times
0

ADM
- 20,406
- 11
- 52
- 83

Darshi Domadiya
- 267
- 3
- 13
-
did you try to use `CardView` ? – Donald Wu Apr 17 '20 at 04:25
-
Does this answer your question? [Android View shadow](https://stackoverflow.com/questions/21211870/android-view-shadow) – ADM Apr 17 '20 at 04:35
4 Answers
4
use MaterialCardView
and use cardElevation
add this in gradle file to use 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>
in your 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>

Jaydeep chatrola
- 2,423
- 11
- 17
-
You can also set elevation programmatically. Definitely the best answer. – gcantoni Apr 17 '20 at 10:33
-
@Jaydeep chatrola MaterialCardView not resolve or not shown in xml – Darshi Domadiya Apr 17 '20 at 13:01
-
-
-
-
0
I think you can try to use cardView
and add onclick
func to act as a button
Inside the cardView
, you need to customize the layout of TextView
, ImageView
and other UI you want.
https://guides.codepath.com/android/using-the-cardview
https://material.io/develop/android/components/cards/
For button shadow, I guess cardView
can add shadow too

Donald Wu
- 698
- 7
- 20
0
<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">

Jaimil Patel
- 1,301
- 6
- 13