Reputation: 467
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
... />
<androidx.cardview.widget.CardView
app:cardCornerRadius="20dp"
android:layout_width="100sp"
android:layout_height="200sp"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" >
<ImageView
android:layout_marginTop="0dp"
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_launcher_background" />
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
But when I create new project a corners is not override. I do not why I have this and how i can repair this
Upvotes: 0
Views: 84
Reputation: 2345
For assigning cornerRadius to CardView just Use
app:cardCornerRadius="10dp"
in your CardView to assign corner's to your cardView . And for Rounded ImageView use RoundedImageView library .
First Step : Add the below dependency to your app level gradle file
implementation 'com.makeramen:roundedimageview:2.3.0'
Second Step : And in your project level gradle file make sure you have inside your repositories block:
repositories {
mavenCentral()
}
Third Step :
Now just replace your ImageView with the RoundedImageView : For eg like this :
com.makeramen.roundedimageview.RoundedImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/imageView1"
android:src="@drawable/photo1"
android:scaleType="fitCenter"
app:riv_corner_radius="30dip"
app:riv_border_width="2dip"
app:riv_border_color="#333333"
app:riv_mutate_background="true"
app:riv_tile_mode="repeat"
app:riv_oval="true" />
Here you can change the corner_radius as you like and also if you want to keep it oval as shape then mark it app:riv_oval as true else mark it as false .
Upvotes: 1