I want to code the below line programmatically in android.
Please any one help me to solve it out.i have search it but could not able to get exact solution.
Thanx in Advance.
android:layout_marginRight="30dp"
I want to code the below line programmatically in android.
Please any one help me to solve it out.i have search it but could not able to get exact solution.
Thanx in Advance.
android:layout_marginRight="30dp"
Try this, you can do that in code like following
TextView forgot_pswrd = (TextView) findViewById(R.id.ForgotPasswordText);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llp.setMargins(0, 0, 30, 0); // llp.setMargins(left, top, right, bottom);
forgot_pswrd.setLayoutParams(llp);
Note: Above code is valid if you are using LinearLayout, if you are using RelativeLayout or FrameLayout then use accordingly. For this addition note, credit goes to biovamp.
You can do like this
TextView tv;
tv=(TextView)findViewById(R.id.YourTextViewID);
tv..setOnTouchListener(this);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llp.setMargins(50, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
forgot_pswrd.setLayoutParams(llp);