1

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"
4

2 回答 2

3
 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.

于 2012-08-30T06:13:59.960 回答
1

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);
于 2012-08-30T06:35:37.877 回答