如何显示下面的屏幕顶部的LinearLayout 100px的?屏幕、LinearLayout、px

2023-09-04 07:15:08 作者:你的话﹏刺痛的回忆

我有一个的FrameLayout(所有画面是佛罗里达州)至极富人一个openGLview并在屏幕顶​​部的标题图片。现在我想显示的两个按钮的菜单,用LinearLayout中创建的。

我的LL菜单必须浮上的FrameLayout,100像素屏幕下方的顶部。

我怎样才能做到这一点?我trye​​d与此code,但是,正在显示菜单100像素屏幕下方的上方不能正常工作,但它是绘画菜单的上半部分,而我不希望出现这种情况,我需要的菜单的上部它没有涂上菜单的颜色。必须是一个浮动菜单。

我敢肯定,还有另一种方式提请下面的屏幕顶部的菜单100像素不画菜单的颜色菜单的上半部分。

我的code(与上部的颜色问题):

  ///////////////子菜单中去shareit ////////////////
    的LinearLayout sharellContainer =新的LinearLayout(本);
    sharellContainer.setOrientation(LinearLayout.HORIZONTAL);
    的LinearLayout sharell =新的LinearLayout(本);
    sharell.setOrientation(LinearLayout.VERTICAL);
    sharell.setLayoutParams(新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
    //LinearLayout.LayoutParams sharellParams =新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);

    份额=新的ImageButton(本);
    选择(份额,R.drawable.but_share_up,R.drawable.but_share_down);
    LinearLayout.LayoutParams shareParams =新LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    shareParams.setMargins(0,0,0,10); //德约联合国非裔恩特雷里奥斯埃斯特波顿ÿ报siguiente
    share.setLayoutParams(shareParams);
    sharell.addView(股);

    网站=新的ImageButton(本);
    选择器(网络,R.drawable.but_web_up,R.drawable.but_web_down);
    sharell.addView(网络);

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

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

。 。

  fl.addView(squareGLSurfaceView);
    fl.addView(RL);
    fl.addView(sharellContainer);
    的setContentView(FL);
 

解决方案

现在的问题是,你正在使用填充,而不是利润率。任何填充得到的观点的背景颜色,边距没有。 你将不得不边缘添加到您给您的视图中的LayoutParams。

android LinearLayout

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);     

解决方案

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.