0

I have declared textview in relative layout with marginleft and marigntop declared with 30dp. But i need to change those marginleft and margintop dynamically inside class file for one particular thing. Help how to do it.

thanks in advance!!!!!111111

Kalaiselvan
  • 408
  • 1
  • 6
  • 14
  • possible duplicate of [In Android, how do I set margins in dp programmatically](http://stackoverflow.com/questions/12728255/in-android-how-do-i-set-margins-in-dp-programmatically) – nbokmans Sep 28 '15 at 09:08

1 Answers1

0
    TextView forgot_pswrd = (TextView) findViewById(R.id.ForgotPasswordText);
    forgot_pswrd.setOnTouchListener(this);     
    LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    llp.setMargins(30, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
    forgot_pswrd.setLayoutParams(llp);

I did this and it worked perfectly. Maybe as you are giving the value in -ve, that's why your code is not working. You just put this code where you are creating the reference of the view.

Muhammad Waleed
  • 2,517
  • 4
  • 27
  • 75