如何以编程方式设置权重按钮 [英] How to programmatically set weight for Button
问题描述
我需要实现对话我通过Java code Android应用程序,所以我不能使用XML。
我有根线的布局,我执行范围搜索栏,那么我还有一个线性布局下根布局,水平方向,在这里我想补充两个按钮在同一行。所以,我需要设置权重为1,宽度为FILL_PARENT和高度WRAP_PARENT。
我如何能做到这一点与Java code?
LinearLayout.LayoutParams P =新LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
p.weight = 1;
rangeSeekBar.setLayoutParams(对);
我不知道哪个视图要设置布局PARAMS上。我刚刚就任rangeSeekbar显示一个例子。如果你需要更改。
在使用的布局PARAMS始终使用root的参数类型。
例。如果你有一个查看
你想在一个 RelativeLayout的
使用 RelativeLayout.LayoutParams PARAMS申请
..
I need to implement Dialog for my Android app through Java code, so I can't use XML.
I have root Linear layout where I implement range seek bar, then I have another Linear Layout under root layout, with horizontal orientation, where I want to add two buttons in same row. So I need to set weight to 1, and width to FILL_PARENT and height to WRAP_PARENT.
How I can do that with Java code?
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
p.weight = 1;
rangeSeekBar.setLayoutParams(p);
I'm not sure which view you want to set the layout params on. I just assumed the rangeSeekbar to show an example. Change if you need.
When using the layout params always use the root's param type..
Ex. if you have a View
you want to apply params to within a RelativeLayout
use RelativeLayout.LayoutParams
..
这篇关于如何以编程方式设置权重按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!