I would like to know if there is any way to change the width
and height
of nested Layout
in android widget xml
programatically just like that of LayoutParams
in normal activity?
I'm planning to make a custom progress bar with the LineraLayouts
hence i need to change the width
of one layout to display the change
The type of the LayoutParams
you must use is specified by the type of Layout that encapsulates the thing you want to change params for.
So for example if you want to change LayoutParams
for your LinearLayout
you need to check what's the Layout type that encapsulates it. In your case LinearLayout
is being encapsulated by RelativeLayout
so you need to use RelativeLayout.LayoutParams
instead of ViewGroup.LayoutParams
.
LinearLayout
inside RelativeLayout
in your xml file (activity_main.xml). Use RelativeLayout.LayoutParams
to solve this issue.
Change this:
ll.setLayoutParams(new ViewGroup.LayoutParams(100,200));
to:
ll.setLayoutParams(new RelativeLayout.LayoutParams(100,200));
You have to use this way to find nested layout and change layout params.
Button button = (Button) findViewById(view.getId());
LinearLayout rLGreen = ((LinearLayout) button.getParent());
rLGreen.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
It may be help you!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.