0

All the view classes on Android are define in rectangle shape.When you touches it detects in the rectangle zone,when you set image it fills the rectangle.How to make a class which is round by default?

Features I am looking for:

  1. Support all the ImageView functions
  2. Square Image input with setImageBitmap or onDraw are converted to round.
  3. Dectect circular touch zone instead of sqaures
  4. Small in size and overhead.
  5. 3rd Party is fine but prefer just use interal library.
shadow_wxh
  • 366
  • 3
  • 17
  • Many components have rounded corners. Check the [material components Library](https://github.com/material-components/material-components-android/blob/master/docs/theming/Shape.md). Also you can apply the `MaterialShapeDrawable` to any view. Finally you can use the `ShapeableImageView` to obtain an Image with rounded corners. Check https://stackoverflow.com/a/60058794/2016562 – Gabriele Mariotti Jun 13 '20 at 14:55
  • It looks like you can draw image with round corners,what about click zones are they round too? – shadow_wxh Jun 13 '20 at 15:36

1 Answers1

0

Create a shape inside your drawable package. // res/drawable/circle.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="0dp"
    android:shape="ring"
    android:thicknessRatio="1.9"
    android:useLevel="false" >
    <solid android:color="@android:color/transparent" />
    <stroke
        android:width="10dp"
        android:color="@android:color/white" />
</shape>

Then create a layer list inside the drawable

    // res/drawable/img.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:drawable="@drawable/circle"/>    
    <item android:drawable="@drawable/ic_launcher"/>

</layer-list>

Then create the image view with layer list

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/img"/>
FxMax
  • 472
  • 1
  • 5
  • 9