generated from gzu-liyujiang/AliyunGradleConfig
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
657d455
commit 39d2b33
Showing
7 changed files
with
254 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
112 changes: 112 additions & 0 deletions
112
library/src/main/java/com/github/gzuliyujiang/RoundCornerImage/RoundCornerImageView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright (c) 2016-present 贵州纳雍穿青人李裕江<[email protected]> | ||
* | ||
* The software is licensed under the Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR | ||
* PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
package com.github.gzuliyujiang.RoundCornerImage; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.Canvas; | ||
import android.graphics.Path; | ||
import android.util.AttributeSet; | ||
import android.widget.ImageView; | ||
|
||
/** | ||
* 圆角图片,支持分别设置上下左右四个角 | ||
* | ||
* @author liyujiang | ||
* @since 2018/2/2 | ||
*/ | ||
public class RoundCornerImageView extends ImageView { | ||
private static final int CORNER_TYPE_ALL = 0; | ||
private static final int CORNER_TYPE_LEFT = 1; | ||
private static final int CORNER_TYPE_TOP = 2; | ||
private static final int CORNER_TYPE_RIGHT = 3; | ||
private static final int CORNER_TYPE_BOTTOM = 4; | ||
private static final int CORNER_TYPE_LEFT_FALLING = 5; | ||
private static final int CORNER_TYPE_RIGHT_FALLING = 6; | ||
private static final float CORNER_SIZE_DIP = 3; | ||
private final Path path = new Path(); | ||
private float width, height; | ||
private final int cornerType; | ||
private final float cornerSize; | ||
|
||
public RoundCornerImageView(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public RoundCornerImageView(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public RoundCornerImageView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
TypedArray t = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerImageView); | ||
cornerType = t.getInteger(R.styleable.RoundCornerImageView_lyj_cornerType, CORNER_TYPE_ALL); | ||
cornerSize = t.getDimension(R.styleable.RoundCornerImageView_lyj_cornerSize, CORNER_SIZE_DIP * getResources().getDisplayMetrics().density); | ||
t.recycle(); | ||
} | ||
|
||
@Override | ||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) { | ||
super.onLayout(changed, left, top, right, bottom); | ||
width = getWidth(); | ||
height = getHeight(); | ||
} | ||
|
||
@Override | ||
protected void onDraw(Canvas canvas) { | ||
if (width > cornerSize && height > cornerSize) { | ||
// 左上点 | ||
path.moveTo(cornerSize, 0); | ||
// 上边线 | ||
path.lineTo(width - cornerSize, 0); | ||
// 右上角 | ||
if (cornerType == CORNER_TYPE_ALL || cornerType == CORNER_TYPE_RIGHT || | ||
cornerType == CORNER_TYPE_TOP || cornerType == CORNER_TYPE_LEFT_FALLING) { | ||
path.quadTo(width, 0, width, cornerSize); | ||
} else { | ||
path.lineTo(width, 0); | ||
} | ||
// 右边线 | ||
path.lineTo(width, height - cornerSize); | ||
// 右下角 | ||
if (cornerType == CORNER_TYPE_ALL || cornerType == CORNER_TYPE_RIGHT || | ||
cornerType == CORNER_TYPE_BOTTOM || cornerType == CORNER_TYPE_RIGHT_FALLING) { | ||
path.quadTo(width, height, width - cornerSize, height); | ||
} else { | ||
path.lineTo(width, height); | ||
} | ||
// 下边线 | ||
path.lineTo(cornerSize, height); | ||
// 左下角 | ||
if (cornerType == CORNER_TYPE_ALL || cornerType == CORNER_TYPE_LEFT || | ||
cornerType == CORNER_TYPE_BOTTOM || cornerType == CORNER_TYPE_LEFT_FALLING) { | ||
path.quadTo(0, height, 0, height - cornerSize); | ||
} else { | ||
path.lineTo(0, height); | ||
} | ||
// 左边线 | ||
path.lineTo(0, cornerSize); | ||
// 左上角 | ||
if (cornerType == CORNER_TYPE_ALL || cornerType == CORNER_TYPE_LEFT || | ||
cornerType == CORNER_TYPE_TOP || cornerType == CORNER_TYPE_RIGHT_FALLING) { | ||
path.quadTo(0, 0, cornerSize, 0); | ||
} else { | ||
path.lineTo(0, 0); | ||
} | ||
canvas.clipPath(path); | ||
} | ||
super.onDraw(canvas); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!-- | ||
~ Copyright (c) 2016-present 贵州纳雍穿青人李裕江<[email protected]> | ||
~ | ||
~ The software is licensed under the Mulan PSL v2. | ||
~ You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
~ You may obtain a copy of Mulan PSL v2 at: | ||
~ http://license.coscl.org.cn/MulanPSL2 | ||
~ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR | ||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR | ||
~ PURPOSE. | ||
~ See the Mulan PSL v2 for more details. | ||
--> | ||
|
||
<resources> | ||
|
||
<declare-styleable name="RoundCornerImageView"> | ||
<attr name="lyj_cornerType" format="enum"> | ||
<enum name="all" value="0" /> | ||
<enum name="left" value="1" /> | ||
<enum name="top" value="2" /> | ||
<enum name="right" value="3" /> | ||
<enum name="bottom" value="4" /> | ||
<enum name="left_falling" value="5" /> | ||
<enum name="right_falling" value="6" /> | ||
</attr> | ||
<attr name="lyj_cornerSize" format="dimension|reference" /> | ||
</declare-styleable> | ||
|
||
</resources> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.