I have a RelativeLayout
in my Android App. Now I want to show an ImageView
in front of that Layout. The problem is that the ImageView
is not in the front, it's a bit transparent and I can see things like EditText
and Button
. I can't change the Layout (setContentView), because the Layout is created dynamically and after setContentView
, the Controls are away.
Asked
Active
Viewed 4,035 times
1

Bhargav Rao
- 50,140
- 28
- 121
- 140

Jan Knoblauch
- 219
- 1
- 3
- 20
-
please post the layout if you can – NullPointerException Feb 03 '14 at 18:52
-
1I agree. Please could you post the layout and also a picture of what it looks like currently? – edwoollard Feb 03 '14 at 18:53
2 Answers
3
You can add view programmatically, and in the way that it will be on the top!
- create id for you top level layout
Now some code (in my case it's relative layout):
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; }

Nicramus
- 606
- 1
- 6
- 19
-
Thanks, that solves my problem. Unfortunately, I wasn't able to try it until now. – Jan Knoblauch Feb 04 '14 at 20:06
1
You can bring it to the front once you insert it.
imageView.bringToFront();
If the image is transparent, you can set a white background to prevent things below it from showing.
imageView.setBackgroundColor(0xFFFFFF);

Aswin Rajendiran
- 3,399
- 1
- 21
- 18