2

I'm looking for a way to dynamically change an elements properties.

For example I want the user of my app to be able to enter a value within my program that will change android:layout_marginTop="blabla" to whatever I want. It doesn't specifically have to be that property, I want to be able to change any property of any element. Is there a way to do this?

Andrew K
  • 21
  • 1

2 Answers2

1

Depends which kind of property you are willing to change. For some you have methods in the View object and for other using LayoutParameters.

You can check the following questions which answers similar stuff:

Community
  • 1
  • 1
Macarse
  • 91,829
  • 44
  • 175
  • 230
0

You can use this way by defining layout params and define it in your view.

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    lp.setMargins(30, 0, 0, 0);

    lp.height = "100";
    lp.width = "100";
    button.setLayoutParams(lp);
krunal shah
  • 16,089
  • 25
  • 97
  • 143