Android自定义View实现不规则图形(6边形) ,可将其做为背景并在上面放置图片,或可将其用作特殊的按钮。实现了滑动功能(点击功能和放缩功能有待实现,有时间将进行完善)
代码如下:
public class custom extends View {
private Bitmap bitmap=null;
private int mWidth;
private int mHeight;
private int mLength;
private Paint mPaint;
private Path mPath;
private float lastDownX,lastDownY;
private WindowManager windowManager;
//View当前的位置
private int rawX = 0;
private int rawY = 0;
//View之前的位置
private int lastX = 0;
private int lastY = 0;
//private float offsetX,offsetY;
//private int sixWidth,sixHeight,sixLength;
//这里三个构造方法都必须实现,否则会报错
public custom(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public custom(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// TODO Auto-generated constructor stub
}
public custom(Context context, AttributeSet attrs) {
super(context, attrs);
//自定义属性
TypedArray typearray=context.obtainStyledAttributes(attrs,R.sty