編輯:關於Android編程
根據給定的頭部模板,截取資源圖。背景圖可支持拖動,縮放,拖動旋轉
定義剪切浮層,實現背景資源圖的操作view
/**
* 初始化繪制筆
*/
private void initRectPaint()
{
mFloatPaint = new Paint();
mFloatPaint.setAlpha(mAlpha);
mFloatPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR));
mEdgePaint = new Paint();
mEdgePaint.setColor(Color.parseColor(#ff000000));
mEdgePaint.setAlpha(mAlpha);
}
@Override
public void draw(Canvas canvas)
{
/** 繪制周圍的背景色 **/
drawEdge(canvas);
/** 繪制中間浮層 **/
canvas.drawBitmap(mCropDrawable, mFloatRect.left, mFloatRect.top,
mFloatPaint);
}
操作圖層手勢
@Override
protected void onDraw(Canvas canvas)
{
canvas.save();
canvas.drawColor(Color.parseColor(#ff1c1c22));
canvas.drawBitmap(mBGHeadBitmap, mFloatRect.left, mFloatRect.top, null);
canvas.drawBitmap(mBGBitmap, mBGgmatrix, null);
mFloatView.draw(canvas);
canvas.restore();
}
//手勢操作
public boolean onTouchEvent(MotionEvent event)
{
switch (event.getAction() & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_DOWN :
eventMode = EventMode.DRAG;
x_down = event.getX();
y_down = event.getY();
savedMatrix.set(mBGgmatrix);
break;
case MotionEvent.ACTION_POINTER_DOWN :
eventMode = EventMode.ZOOM;
oldDist = spacing(event);
mRotation = rotation(event);
savedMatrix.set(mBGgmatrix);
midPoint(midPoint, event);
break;
case MotionEvent.ACTION_MOVE :
if (eventMode == EventMode.DRAG)
{
matrix1.set(savedMatrix);
matrix1.postTranslate(event.getX() - x_down, event.getY()
- y_down);
mBGgmatrix.set(matrix1);
invalidate();
} else if (eventMode == EventMode.ZOOM)
{
float rotation = rotation(event) - mRotation;
float newDist = spacing(event);
float scale = newDist / oldDist;
/** 縮放 **/
float values[] = new float[9];
{
matrix1.set(savedMatrix);
matrix1.postScale(scale, scale, midPoint.x, midPoint.y);
}
/** 旋轉 **/
matrix1.postRotate(rotation, midPoint.x, midPoint.y);
mBGgmatrix.set(matrix1);
invalidate();
}
break;
case MotionEvent.ACTION_UP :
case MotionEvent.ACTION_POINTER_UP :
eventMode = EventMode.NONE;
break;
}
return true;
}
獲取剪切圖片
Bitmap tmpBitmap = Bitmap.createBitmap(mScrrenWidth, mScrrenHeight,
Config.ARGB_8888); // 背景圖片
Canvas canvas = new Canvas(tmpBitmap); // 新建畫布
canvas.drawBitmap(mBGHeadBitmap, mFloatRect.left, mFloatRect.top, null);
canvas.drawBitmap(mBGBitmap, mBGgmatrix, null); // 畫圖片
canvas.save(Canvas.ALL_SAVE_FLAG); // 保存畫布
canvas.restore();
Bitmap ret = Bitmap.createBitmap(tmpBitmap, mFloatRect.left,
mFloatRect.top, mFloatRect.width(), mFloatRect.height(), null,
true);
tmpBitmap.recycle();
tmpBitmap = null;
Bitmap newRet = Bitmap.createBitmap(mFloatRect.width(),
mFloatRect.height(), Config.ARGB_8888);
Canvas canvasHead = new Canvas(newRet);
canvasHead.drawBitmap(ret, 0, 0, null);
Paint paintHead = new Paint();
paintHead.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
Bitmap crop = BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.headmask);
canvasHead.drawBitmap(crop, 0, 0, paintHead);
return newRet;
@author dujinyang難得有時間上來寫博客。fragment雖然好用,但個人還是覺得有利有弊。網上大都說切換狀態,有挺多問題,有很多種解決方案。第
近日,微信悄然上線了個人公眾號改名功能,據悉,微信在原賬號名稱下方會有一行“個人類賬號一年內可主動修改一次名稱”的標注,每年只有一次
導航抽屜(navigationdrawer)是一個從屏幕左邊滑入的面板,用於顯示應用的主要導航項目。用戶可以通過在屏幕左邊緣滑入或者觸摸操作欄的應用圖標打開導航抽屜。導航
什麼是SplashSplash也就是應用程序啟動之前先啟動一個畫面,上面簡單的介紹應用程序的廠商,廠商的LOGO,名稱和版本等信息,多為一張圖片,顯示幾秒鐘後會自動消息,