我的Android应用中有RelativeLayout
。现在我想在该布局前面显示ImageView
。问题是ImageView
不在前面,它有点透明,我可以看到EditText
和Button
之类的内容。我无法更改布局(setContentView),因为布局是动态创建的,在setContentView
之后,控件不在。
答案 0 :(得分:3)
您可以通过编程方式添加视图,以及它在顶部的方式!
现在有些代码(在我的例子中是相对布局):
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;
}
答案 1 :(得分:0)
插入后,您可以将它带到前面。
imageView.bringToFront();
如果图像是透明的,您可以设置白色背景以防止其下方显示。
imageView.setBackgroundColor(0xFFFFFF);