-
Notifications
You must be signed in to change notification settings - Fork 187
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
yuqirong
committed
Mar 3, 2017
1 parent
0de6b01
commit 034192e
Showing
5 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
app/src/main/java/com/yuqirong/cardswipeview/RoundImageView.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,61 @@ | ||
package com.yuqirong.cardswipeview; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.Canvas; | ||
import android.graphics.Path; | ||
import android.graphics.RectF; | ||
import android.util.AttributeSet; | ||
import android.widget.ImageView; | ||
|
||
/** | ||
* @author maomao | ||
* @email qirong.yu@jubaobar.com | ||
* @date 2017-3-3 | ||
*/ | ||
|
||
public class RoundImageView extends ImageView { | ||
|
||
private Path mPath; | ||
private RectF mRectF; | ||
private float[] rids = new float[8]; | ||
|
||
public RoundImageView(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public RoundImageView(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public RoundImageView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.RoundImageView); | ||
float mRadius = array.getDimension(R.styleable.RoundImageView_radius, 10); | ||
rids[0] = mRadius; | ||
rids[1] = mRadius; | ||
rids[2] = mRadius; | ||
rids[3] = mRadius; | ||
rids[4] = 0f; | ||
rids[5] = 0f; | ||
rids[6] = 0f; | ||
rids[7] = 0f; | ||
array.recycle(); | ||
mPath = new Path(); | ||
} | ||
|
||
@Override | ||
protected void onDraw(Canvas canvas) { | ||
mPath.reset(); | ||
mPath.addRoundRect(mRectF, rids, Path.Direction.CW); | ||
canvas.clipPath(mPath); | ||
super.onDraw(canvas); | ||
} | ||
|
||
@Override | ||
protected void onSizeChanged(int w, int h, int oldw, int oldh) { | ||
super.onSizeChanged(w, h, oldw, oldh); | ||
mRectF = new RectF(0, 0, w, h); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<declare-styleable name="RoundImageView"> | ||
<attr name="radius" format="reference|dimension" /> | ||
</declare-styleable> | ||
</resources> |
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