我正试图在彼此之上放置两张图片。最重要的是透明的。在他们之上,我试图添加一个透明的画布,以便用户可以绘制,键入,无论他们需要做什么,底部的两个图像都可见。分层图像加上画布
所以我可以得到两个图像显示或只是画布。每次我尝试显示画布时,似乎都会覆盖覆盖它们的两幅图像。
这里是我迄今为止..
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);
有什么建议吗?
我必须等待17个小时才能接受我自己的答案...... Don'y很好地说明了这些规则... – George 2011-04-29 00:30:13
阅读[this] (http://meta.stackexchange.com/questions/6044/why-must-i-wait-2-days-before-accepting-my-own-answer)找出原因。 – dandan78 2011-04-29 16:47:58