加入圆角图片

This commit is contained in:
zengfantian 2015-04-07 23:41:42 +08:00
parent d89a154f5a
commit cde607350f
2 changed files with 156 additions and 23 deletions

View File

@ -3,6 +3,7 @@
<!-- view_pull_refresh(start) -->
<declare-styleable name="PullToRefresh">
<!-- A drawable to use as the background of the Refreshable View -->
<attr name="ptrRefreshableViewBackground" format="reference|color" />
<!-- A drawable to use as the background of the Header and Footer Loading Views -->
@ -62,47 +63,51 @@
<attr name="ptrDrawableBottom" format="reference" />
</declare-styleable>
<!-- view_pull_refresh(end) -->
<!-- 圆角进度条(开始) -->
<declare-styleable name="RoundProgressBar">
<attr name="roundColor" format="color"/>
<attr name="roundProgressColor" format="color"/>
<declare-styleable name="RoundProgressBar">
<attr name="roundColor" format="color" />
<attr name="roundProgressColor" format="color" />
<attr name="roundWidth" format="dimension"></attr>
<attr name="textColor" format="color" />
<attr name="textSize" format="dimension" />
<attr name="max" format="integer"></attr>
<attr name="textColor" format="color" />
<attr name="textSize" format="dimension" />
<attr name="max" format="integer"></attr>
<attr name="textIsDisplayable" format="boolean"></attr>
<attr name="style">
<enum name="STROKE" value="0"></enum>
<enum name="FILL" value="1"></enum>
</attr>
</declare-styleable>
</declare-styleable>
<!-- 圆角进度条(结束) -->
<!-- 圆形图片(开始) -->
<declare-styleable name="RoundedImageView">
<declare-styleable name="RoundedImageView">
<attr name="border_thickness" format="dimension"></attr>
<attr name="border_outside_color" format="color"/>
<attr name="border_inside_color" format="color"/>
</declare-styleable>
<attr name="border_outside_color" format="color" />
<attr name="border_inside_color" format="color" />
</declare-styleable>
<!-- 圆形图片(结束) -->
<!-- 圆角图片(开始) -->
<declare-styleable name="RoundAngleImageView">
<attr name="rWidth" format="dimension" />
<attr name="rHeight" format="dimension" />
</declare-styleable>
<!-- 圆角图片(结束) -->
<!-- 滑动删除列表 -->
<declare-styleable name="swipelistviewstyle">
<attr name="right_width" format="dimension"></attr>
<declare-styleable name="swipelistviewstyle">
<attr name="right_width" format="dimension"></attr>
</declare-styleable>
<!-- TextViewRadioButton/CheckBox共通value开始 -->
<declare-styleable name="TextView" >
<attr name="key" format="string"/>
<attr name="value" format="string"/>
</declare-styleable>
<!-- TextViewRadioButton/CheckBox共通value结束 -->
<declare-styleable name="TextView">
<attr name="key" format="string" />
<attr name="value" format="string" />
</declare-styleable>
<!-- TextViewRadioButton/CheckBox共通value结束 -->
<declare-styleable name="PullScrollView">
<attr name="header" format="reference" />

View File

@ -0,0 +1,128 @@
package com.zftlive.android.view;
import com.zftlive.android.R;
import android.widget.ImageView;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.util.AttributeSet;
/**
* 圆角图片
* @author 曾繁添
* @version 1.0
*
*/
public class RoundAngleImageView extends ImageView {
private Paint paint;
private int roundWidth = 5;
private int roundHeight = 5;
private Paint paint2;
public RoundAngleImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs);
}
public RoundAngleImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public RoundAngleImageView(Context context) {
super(context);
init(context, null);
}
private void init(Context context, AttributeSet attrs) {
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.RoundAngleImageView);
roundWidth = a.getDimensionPixelSize(
R.styleable.RoundAngleImageView_rWidth, roundWidth);
roundHeight = a.getDimensionPixelSize(
R.styleable.RoundAngleImageView_rHeight, roundHeight);
} else {
float density = context.getResources().getDisplayMetrics().density;
roundWidth = (int) (roundWidth * density);
roundHeight = (int) (roundHeight * density);
}
paint = new Paint();
paint.setColor(Color.WHITE);
paint.setAntiAlias(true);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
paint2 = new Paint();
paint2.setXfermode(null);
}
@Override
public void draw(Canvas canvas) {
Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(),
Config.ARGB_8888);
Canvas canvas2 = new Canvas(bitmap);
super.draw(canvas2);
drawLiftUp(canvas2);
drawRightUp(canvas2);
drawLiftDown(canvas2);
drawRightDown(canvas2);
canvas.drawBitmap(bitmap, 0, 0, paint2);
bitmap.recycle();
}
private void drawLiftUp(Canvas canvas) {
Path path = new Path();
path.moveTo(0, roundHeight);
path.lineTo(0, 0);
path.lineTo(roundWidth, 0);
path.arcTo(new RectF(0, 0, roundWidth * 2, roundHeight * 2), -90, -90);
path.close();
canvas.drawPath(path, paint);
}
private void drawLiftDown(Canvas canvas) {
Path path = new Path();
path.moveTo(0, getHeight() - roundHeight);
path.lineTo(0, getHeight());
path.lineTo(roundWidth, getHeight());
path.arcTo(new RectF(0, getHeight() - roundHeight * 2,
0 + roundWidth * 2, getHeight()), 90, 90);
path.close();
canvas.drawPath(path, paint);
}
private void drawRightDown(Canvas canvas) {
Path path = new Path();
path.moveTo(getWidth() - roundWidth, getHeight());
path.lineTo(getWidth(), getHeight());
path.lineTo(getWidth(), getHeight() - roundHeight);
path.arcTo(new RectF(getWidth() - roundWidth * 2, getHeight()
- roundHeight * 2, getWidth(), getHeight()), 0, 90);
path.close();
canvas.drawPath(path, paint);
}
private void drawRightUp(Canvas canvas) {
Path path = new Path();
path.moveTo(getWidth(), roundHeight);
path.lineTo(getWidth(), 0);
path.lineTo(getWidth() - roundWidth, 0);
path.arcTo(new RectF(getWidth() - roundWidth * 2, 0, getWidth(),
0 + roundHeight * 2), -90, 90);
path.close();
canvas.drawPath(path, paint);
}
}