I need to implement Dialog for my Android app through Java code, so I can't use XML.
I have root LinearLayout
where I implement range seek bar, then I have another LinearLayout
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_CONTENT
.
How I can do that with Java code?
an easier way:
You can pass it in as part of the LinearLayout.LayoutParams constructor: Did you mean wrap_content?
1.0f is the weight
Is not using XML a requirement? If not, you could always build your layout in XML and then use a
LayoutInflater
at run-time to build up your view hierarchy and pass that tosetView()
on your dialog.For example:
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 aRelativeLayout
useRelativeLayout.LayoutParams
..