我正在尝试在具有其他元素的 RelativeLayout 顶部的动态位置绘制图像。我尝试创建一个扩展 View 的类并将此视图添加到 RelativeLayout 但图像只是屏幕上显示的东西。RelativeLayout 中的其他元素不可见。
这是视图类
@Override
protected void onDraw (Canvas canvas) {
super.onDraw(canvas);
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(myBitmap, 50,50, null);
}
这是在 Activity 的 onCreate
mainLayout = (RelativeLayout)findViewById(R.id.main_tutorial_layout);
mainLayout.addView( new DrawAnimationTutotial(getApplicationContext()));
mainLayout.invalidate();