Question

I have a FrameLayout (all the screen is the FL) wich haves a openGLview and a header image on the top of the screen. Now i want to display a menu of two buttons, created with a LinearLayout.

My LL Menu must be floating on the framelayout, 100px below the top of the screen.

How can i achieve that? i tryed with this code, but is not working properly, the Menu is being displayed 100px below the top of the screen but it is painting the upper part of the menu, and i dont want that, i need that the upper part of the menu it's not painted with the colour of the menu. Must be a floating menu.

I'm sure that there is another way to draw the menu 100px below the top of the screen without painting the upper part of the menu with the colour of the menu.

My code (with the upper part colour problem):

        ///////////////sub menu de shareit////////////////
    LinearLayout sharellContainer = new LinearLayout(this);
    sharellContainer.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout sharell = new LinearLayout(this);
    sharell.setOrientation(LinearLayout.VERTICAL);
    sharell.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    //LinearLayout.LayoutParams sharellParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    //sharellParams.gravity=Gravity.CENTER; 
    sharell.setPadding(10, shareit.getHeight()+80, 10, 10);
    sharell.setBackgroundColor(0xFF383838);
    //sharell.setLayoutParams(sharellParams);

    share= new ImageButton(this);
    selector(share, R.drawable.but_share_up,R.drawable.but_share_down);
    LinearLayout.LayoutParams shareParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    shareParams.setMargins(0, 0, 0, 10); //dejo un espacio entre este botón y el siguiente
    share.setLayoutParams(shareParams);
    sharell.addView(share);

    web= new ImageButton(this);
    selector(web, R.drawable.but_web_up,R.drawable.but_web_down);
    sharell.addView(web);

    sharellContainer.addView(sharell);
    sharellContainer.setGravity(Gravity.RIGHT); 

    //////////////////////////////////////////////////

. . .

        fl.addView(squareGLSurfaceView);
    fl.addView(rl);
    fl.addView(sharellContainer);
    setContentView(fl);     
Was it helpful?

Solution

The problem is that you are using padding rather than margins. Any padding gets the background color of the view, margins do not.
You will have to add the margins to to the LayoutParams that you give to your view.

OTHER TIPS

This will be very easy if you use an XML layout. You can also view what you are creating and set individual properties. This also allows you to separate your logic from your views and adhere to the MVVM design pattern so future updates are easier to perform, giving you a more flexible system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top