I have a CardView
with rounded corners, I want to have an ImageView
at the top like shown in the example taken from the material design guidelines
I solved the problem with setting
1) app:cardUseCompatPadding="false"
2) setting a rounded imageView
background
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="4dp" />
</shape>
I got this to work by putting a RoundedImageView
inside of a CardView
. Also you need to set the appropriate CardView
attributes.
https://medium.com/@etiennelawlor/layout-tips-for-pre-and-post-lollipop-bcb2e4cdd6b2#.kmb24wtkk
i try to using combination with cardview and imageview, so it will be like this :
android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:cardCornerRadius="8dp"
android:elevation="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/kmp_warna1"
android:scaleType="centerCrop"/>
</android.support.v7.widget.CardView>
I just adding the corner radius and elevation attribute on cardview, and scaletype = centerCrop on image view
Hope it will help
Make a bck_rounded.xml
in drawable
folder. Give it a radius that is same as the card_view.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="4dp" />
</shape>
Apply inside your imageView: android:background="@drawable/bck_rounded"