0

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

silverFoxA
  • 4,549
  • 7
  • 33
  • 73

2 Answers2

0

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));
Garima Mathur
  • 3,312
  • 3
  • 18
  • 32
  • but how do you define which layout you want to change (i have already mentioned i have nested layout)? and i'm asking in case of widgets not simple activity – silverFoxA Jun 07 '15 at 08:46
  • But i ain't asking for activity, please read the question carefully, if it were activity i wouldn't have asked in the first case – silverFoxA Jun 07 '15 at 11:39
-1

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!!

Garima Mathur
  • 3,312
  • 3
  • 18
  • 32
  • Please read the question, i'm not asking how to do it in case of `activity` rather i'm asking how to do the process in case of `widget` – silverFoxA Jun 07 '15 at 11:41