The login
registered
Write an article
Home page
Download the APP

Android rounded corner ViewGrup/View library, cure design rounded corner disease!

The small basket

Android rounded corner ViewGrup/View library, cure design rounded corner disease!

Project Address:RoundCorners

More commonly used View group and View rounded corner implementation, a cure of design rounded corner disease.

Demo

Results the preview

The characteristics of

  • LinearLayout, RelativeLayout, and FrameLayout support rounded corners
  • ImageView, TextView, and View support rounded corners
  • CircleImageView
  • Using XML for configuration is simple to use
  • .

Basic usage

Add the JitPack repository to build. Gradle in the root directory of your project:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}
Copy the code

Step 2. Add project dependencies

Dependencies {implementation 'com. Making. KuangGang: RoundCorners: 1.0.1'}Copy the code

Step 3. Add the required RoundCorners to the layout file

<com.kproduce.roundcorners.CircleImageView android:layout_width="200dp" android:layout_height="200dp" android:layout_marginTop="20dp" android:src="@mipmap/ic_test" /> <com.kproduce.roundcorners.RoundImageView android:layout_width="200dp" android:layout_height="200dp" android:scaleType="centerCrop" android:src="@mipmap/ic_test" app:rRadius="30dp"/> <com.kproduce.roundcorners.RoundTextView android:layout_width="200dp" android:layout_height="100dp"  android:background="@android:color/holo_blue_dark" android:gravity="center" android:text="Hello!" android:textColor="@android:color/white" android:textSize="40sp" app:rRightRadius="30dp" /> <com.kproduce.roundcorners.RoundRelativeLayout android:layout_width="200dp" android:layout_height="200dp" app:rTopRightRadius="30dp" app:rBottomRightRadius="30dp"> <View android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/holo_blue_dark" /> </com.kproduce.roundcorners.RoundRelativeLayout> <com.kproduce.roundcorners.RoundTextView android:layout_width="200dp" android:layout_height="100dp" android:background="@android:color/holo_blue_dark" android:gravity="center" android:text="Hello!" Android :textColor=" @Android :color/white" Android :textSize=" 40SP "APP :rLeftRadius=" 50DP" app:rRightRadius=" 50DP "/>Copy the code

Supported properties and methods

The property name meaning The default value
rRadius Set the radius of the four corners uniformly 0dp
rLeftRadius The radius of the left two corners 0dp
rRightRadius The radius of the right two corners 0dp
rTopRadius The radius of the top two corners 0dp
rBottomRadius The radius of the bottom two corners 0dp
rTopLeftRadius Top left corner radius 0dp
rTopRightRadius Radius of rounded corner in upper right corner 0dp
rBottomLeftRadius Lower left corner radius 0dp
rBottomRightRadius Lower right corner radius 0dp

Principle of shallow solution

Android View drawing process. View rendering take a look at this article, the code version is earlier, but the logic is basically the same.

  1. Use Path’s addRoundRect method to set the radius of the fillet to be clipped.
  2. All views and viewgroups are drawn by the Draw method, which cuts the canvas using the Path used in the first step after the draw.
  3. Note the reduction in object creation in DRAW.

Version of the record

The version number Update the content
1.0.1 1. Fix the black box of rounded corner View in the earlier version system

2. Increase CircleImageView
1.0.0 First Version