0

I have some view defined in my layout xml. e.g.

<ProgressBar
android:id="@+id/viewScanProgressWheel"
android:layout_width="150dp"
android:layout_height="@dimen/pbHeight"/>

Now, later at any point in time, can I change the height or width of the view, like changing the value in dimens or using some custom attributes?

P.S. I want the values to be changed in xml, not just on UI. So that all the calculations need not be done everytime through java side.

Sathish
  • 33
  • 4
Rajkiran
  • 15,845
  • 24
  • 74
  • 114
  • 1
    Have a look at this: http://stackoverflow.com/questions/5191099/how-to-set-relativelayout-layout-params-in-code-not-in-xml Use RelativeLayoutParams / LinearLayoutParams, it must be like the parent view – Francesco verheye May 22 '14 at 10:09
  • http://stackoverflow.com/questions/11202474/how-to-dynamically-modify-android-layout-xml – Francesco verheye May 22 '14 at 10:11

3 Answers3

0

you mean changing the value of dimens in dimen.xml?
i think you can't,

but you can change the width/height etc programatically using LayoutParams

yourView.setLayoutParams(new LayoutParams(width,height));


do take note, that you must assign the LayoutParam from the package of the view's parent
ex:
your view is a child of LinearLayout, make sure it's LinearLayout.LayoutParams etc, to avoid exceptions

check the reference for more parameters in different LayoutParams by its type of ViewGroup

Ferry Tan
  • 218
  • 2
  • 10
0

Try this yourView.getLaoutParams().heigth = x; or yourView.getLaoutParams().width = x;, and depending when are you calling it you may have to make yourView.requestLayout(); before

miibpa
  • 235
  • 1
  • 4
  • 15
0

You can always change layout size programmatically using:

view.layout(0, 0, viewWidth, viewHeight);
tadvas
  • 131
  • 1
  • 13