简体   繁体   English

如何获取线性布局以填充Android中的父页面

[英]How can I get the linear layout to fill the parent page in Android

页面控制器

I have created a pagecontroller application and added it on my page in its own linear layout. 我已经创建了一个pagecontroller应用程序,并将其以自己的线性布局添加到我的页面上。 However, I can not get the layout width to fill the entire parent page.. This is my code: 但是,我无法获得布局宽度来填充整个父页面。这是我的代码:

pagecontrol = new LinearLayout(this.context);
pagecontrol.setOrientation(LinearLayout.HORIZONTAL);
pagecontrol.setGravity(Gravity.CENTER_HORIZONTAL);

params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.FILL_PARENT);
pagecontrol.addView(btn,params);

public LinearLayout getView() {
        return pagecontrol;
    }

I have attached the screenshot of the page. 我已经附上了页面的截图。 Could anyone please advise? 有人可以建议吗?

Thanks in advance. 提前致谢。

params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT);

You must use these properties. 您必须使用这些属性。

android:layout_width="fill_parent"
android:layout_height="fill_parent"
params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.FILL_PARENT); 

replace WRAP_CONTENT with FILL_PARENT it will work 用FILL_PARENT替换WRAP_CONTENT它将起作用

Please check the height and width of layout if you take the outer layout of your linear layout. 如果采用线性布局的外部布局,请检查布局的高度和宽度。

Change it: 更改:

android:layout_width="fill_parent"
android:layout_height="fill_parent"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM