我的Android应用程序中有一个RelativeLayout
。现在我想在布局前面显示一个ImageView
。问题是ImageView
不在前面,它有点透明,我可以看到像EditText
和Button
这样的东西。我无法更改布局(setContentView),因为布局是动态创建的,在setContentView
之后,控件不在。
您可以以编程方式添加视图,并以它将在顶部的方式添加!
RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.relative_layout_id);
ImageView imageView = new ImageView(context)
Drawable rightArrowBlackDrawable = getResources().getDrawable(R.drawable.image);
imageView.setLayoutParams(getLayoutParams());
relativeLayout.addView(imageView);
imageView.bringToFront();
//here just example layout params, use yours params ;-)
private RelativeLayout.LayoutParams getLayoutParams() {
RelativeLayout.LayoutParams layoutParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
return layoutParams;
}
插入后,您可以将它带到前面。
imageView.bringToFront();
如果图像是透明的,您可以设置白色背景以防止其下方的内容显示。
imageView.setBackgroundColor(0xFFFFFF);