1

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.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Jan Knoblauch
  • 219
  • 1
  • 3
  • 20

2 Answers2

3

You can add view programmatically, and in the way that it will be on the top!

  1. create id for you top level layout
  2. 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
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