Skip to content

Commit

Permalink
Merge pull request GcsSloop#39 from dengyuhan/master
Browse files Browse the repository at this point in the history
修复android8.1以上 圆角圆形剪裁失效的问题
  • Loading branch information
GcsSloop authored Nov 20, 2018
2 parents ead2052 + 2da96e0 commit f0fd17c
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 15 deletions.
Binary file added Img/Demo_2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions RCLayout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
minSdkVersion 14
targetSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Android 通用圆角布局,快速实现圆角需求。
## 效果预览

<p>
<img src="http://ww1.sinaimg.cn/large/005Xtdi2gy1fqbgk8pmevg309u0ghwz9.gif" width="300"/> <img src="https://ww4.sinaimg.cn/large/006tKfTcly1fk7twywj5oj30u01fewka.jpg" width="292"/>
<img src="Img/Demo_2.gif" height="542"/> <img src="Img/Demo.jpeg" height="542"/>
</p>

## 支持的特性
Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.gcssloop.roundcornerlayouttest"
minSdkVersion 19
targetSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -46,7 +46,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:appcompat-v7:28.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile project(':rclayout')
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity android:name=".AntiAliasActivity" />
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ private int getProgressRadius(int progress) {
}

public void clickAntiAlias(View view) {
startActivity(new Intent(this,AntiAliasActivity.class));
startActivity(new Intent(this, AntiAliasActivity.class));
}

public void clickExample(View view) {
startActivity(new Intent(this, MainActivity.class));
}


Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
android:layout_height="match_parent"
android:background="@color/colorActivityBackground">

<TextView
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="clickExample"
android:text="其它示例"
android:textColor="@android:color/white" />

<TextView
android:layout_alignParentRight="true"
android:id="@+id/tv_antialias"
Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.Checkable;
import android.widget.RelativeLayout;
Expand Down
28 changes: 23 additions & 5 deletions rclayout/src/main/java/com/gcssloop/widget/helper/RCHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.Region;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Checkable;
Expand Down Expand Up @@ -122,12 +123,19 @@ public void refreshRegion(View view) {
float d = areas.width() >= areas.height() ? areas.height() : areas.width();
float r = d / 2;
PointF center = new PointF(w / 2, h / 2);
mClipPath.addCircle(center.x, center.y, r, Path.Direction.CW);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {
mClipPath.addCircle(center.x, center.y, r, Path.Direction.CW);

mClipPath.moveTo(0, 0); // 通过空操作让Path区域占满画布
mClipPath.moveTo(w, h);
} else {
float y = h / 2 - r;
mClipPath.moveTo(areas.left, y);
mClipPath.addCircle(center.x, y + r, r, Path.Direction.CW);
}
} else {
mClipPath.addRoundRect(areas, radii, Path.Direction.CW);
}
mClipPath.moveTo(0, 0); // 通过空操作让Path区域占满画布
mClipPath.moveTo(w , h);
Region clip = new Region((int) areas.left, (int) areas.top,
(int) areas.right, (int) areas.bottom);
mAreaRegion.setPath(mClipPath, clip);
Expand All @@ -147,10 +155,20 @@ public void onClipDraw(Canvas canvas) {
mPaint.setStyle(Paint.Style.STROKE);
canvas.drawPath(mClipPath, mPaint);
}
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
mPaint.setColor(Color.WHITE);
mPaint.setStyle(Paint.Style.FILL);
canvas.drawPath(mClipPath, mPaint);

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
canvas.drawPath(mClipPath, mPaint);
} else {
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));

final Path path = new Path();
path.addRect(0, 0, (int) mLayer.width(), (int) mLayer.height(), Path.Direction.CW);
path.op(mClipPath, Path.Op.DIFFERENCE);
canvas.drawPath(path, mPaint);
}
}


Expand Down

0 comments on commit f0fd17c

Please sign in to comment.