分层图像加上帆布 [英] layered images plus canvas
问题描述
我想打好两张图在彼此的顶部。最上面的一个是透明的。在上面我试图添加一个透明画布,使用户可以得出,类型,无论他们需要做的,底部的两个图像是可见的。
I am trying to lay two picture on top of each other. Top one is transparent. On top of them I am trying to add a transparent canvas so the user can draw, type, whatever they need to do and the bottom two images are visible.
所以我可以得到两个图像显示出来,或只是在画布上。每次我试图显示它似乎在画布上喜欢它,是对[两个图像覆盖其中的第
So I can get the two images to show up or just the canvas. Everytime I try to display the canvas it seems like it is on to[p of the two images covering them.
下面是我迄今为止..
Here is what I have so far..
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);
Now I am suspecting that the canvas is not part of the relative layout. Could that be the problem? If yes, I can't do relativeLayout.addView(mCanvas,lp);
有什么建议?
推荐答案
对不起不得不等待八个小时回答我的问题。
Sorry had to wait eight hours to answer my own question.
我能解决这个问题。我创建了一个类。
I was able to fix the problem. I created a class.
public class newClass extends View {
public newClass (Context context){ super(context); }
...
@Override protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.TRANSPARENT); }
然后,所有我必须做的。
Then all I had to do
final newClass myCanvas = new newClass (this);
relativeLayout.addView(myCanvas,lp2);
做工精细...
Works fine...
这篇关于分层图像加上帆布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!