How to have a curcular ImageView. This is my xml
<RelativeLayout
android:id="@+id/imgUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="@drawable/circle_border">
<ImageView
android:id="@+id/studentimg"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_margin="9dp"
android:adjustViewBounds="true"
android:background="@drawable/circlepf"
android:padding="3dp"
android:scaleType="centerInside"
android:src="@drawable/ic_profile" />
</RelativeLayout>
this is my problem image sample
but I want this image to show in circular view
You can use the Material Components Library .
With the version 1.2.0-alpha03
there is the new ShapeableImageView
.
<com.google.android.material.imageview.ShapeableImageView
...
android:scaleType="centerInside"
android:adjustViewBounds="true"
app:shapeAppearanceOverlay="@style/circleImageView"
app:srcCompat="@drawable/ic_profile" />
with:
<style name="circleImageView" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
I recently found this library in Github. https://github.com/christophesmet/android_maskable_layout
Any layout or imageview wrapped in the MaskableFrameLayout will be cropped in the desired shape by just providing the required shape to the mask attribute of the maskLayout as shown below:
<com.christophesmet.android.views.maskableframelayout.MaskableFrameLayout
android:id="@+id/frm_mask_animated"
android:layout_width="100dp"
app:porterduffxfermode="DST_IN"
app:mask="@drawable/drawable_circular"
android:layout_height="100dp">
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/unicorn"/>
</com.christophesmet.android.views.maskableframelayout.MaskableFrameLayout>
Also, you have Circleimageview library available : https://github.com/hdodenhof/CircleImageView
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.