我正在尝试将两张图片放在一起。顶部是透明的。在它们之上,我正在尝试添加一个透明画布,以便用户可以绘制、键入、他们需要做的任何事情,并且底部的两个图像是可见的。
所以我可以让两个图像显示或只是画布。每次我尝试显示画布时,它似乎都在覆盖它们的两个图像中。
这是我到目前为止所拥有的..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
..... some code to set up the paint
}
private Paint mPaint;
private MaskFilter mEmboss;
private MaskFilter mBlur;
public class MyView extends View {
private static final float MINP = 0.25f;
private static final float MAXP = 0.75f;
private Bitmap mBitmap;
private Canvas mCanvas;
private Path mPath;
private Paint mBitmapPaint;
public MyView(Context c) {
super(c);
// Creating a new relative layout add the definition again.
RelativeLayout relativeLayout = new RelativeLayout(TwoPicksOnEachOther.this);
// Setting the orientation to vertical
////relativeLayout.setOrientation(LinearLayout.VERTICAL);
// Creating Fish image
final ImageView iv = new ImageView(TwoPicksOnEachOther.this);
iv.setImageResource(R.drawable.fish2);
// relative layout parameters
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
//iv.setId(1);
relativeLayout.addView(iv,lp);
// Creating transparent image with boat.
final ImageView iv2 = new ImageView(TwoPicksOnEachOther.this);
iv2.setImageResource(R.drawable.ctdeasytwo);
//iv2.setId(2);
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
relativeLayout.addView(iv2,lp2);
mBitmap = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888);
//mBitmap = BitmapFactory.decodeResource(getResources(),
// R.drawable.ctdeasytwo);
mCanvas = new Canvas(mBitmap);
// mCanvas.drawBitmap(mBitmap, 10, 10, null);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.TRANSPARENT);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
................... More code to manage touch events.
现在我怀疑画布不是相对布局的一部分。这可能是问题吗?如果是,我不能做 relativeLayout.addView(mCanvas,lp);
有什么建议么?