這是我的條紋解決方案,爲了更好地理解
XML第一截圖:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bck"
android:orientation="vertical" >
<View
android:id="@+id/view1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/view" />
<com.example.stackoverflow.CustomView
android:id="@+id/CustomView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/imageview" />
</RelativeLayout>
MainActivity:
public class MainActivity extends Activity implements OnClickListener{
private CustomView imageView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView = (CustomView)findViewById(R.id.CustomView1);
imageView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
imageView.drawCircle();
}
}
自定義視圖:
public class CustomView extends ImageView {
private Canvas mCanvas;
private Paint mBitmapPaint;
private Paint mPaint;
private Bitmap mBitmap;
public CustomView(Context context) {
super(context);
initialize();
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
initialize();
}
public CustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initialize();
}
private void initialize() {
if (!isInEditMode()) {
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
mBitmapPaint.setStyle(Style.STROKE);
mPaint = new Paint();
mPaint.setStyle(Style.FILL);
mPaint.setStrokeWidth(50);
mPaint.setMaskFilter(null);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
reset();
}
}
public void reset(){
Bitmap bmp = ((BitmapDrawable)getDrawable()).getBitmap();
mBitmap = bmp.copy(Bitmap.Config.ARGB_8888, true);
this.setVisibility(View.VISIBLE);
mCanvas = new Canvas(mBitmap);
}
public void drawCircle(){
mCanvas.drawCircle(this.getWidth()/2, this.getHeight()/2, this.getWidth()/2, mPaint);
//this.setImageBitmap(mBitmap);
this.invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
if (isInEditMode()) {
super.onDraw(canvas);
}
else {
//super.onDraw(canvas);
mBitmapPaint.setColor(0xFF000000);
if(mBitmap != null){
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
}
}
}
}
通知評論部分,你可以只設置你的透明圖像繪製或重繪像我一樣,這取決於你的其他需求。另請注意,PNG圖像已經有Alpha通道。
希望這可以幫助和享受您的工作。
你能後的XML? – Niko
考慮到你的問題,這應該是自動的,最近做了一些項目,我只是把imageview放在其他組件上,然後用你的手指擦除圖像,沒什麼特別的。提供更多信息,如xml或您可以共享的內容可能還有其他一些問題。 –
是ImageView的位圖背景或源代碼。你確定這些觀點重疊嗎? – Blackbelt