How to Change Margin of TextView

前端 未结 8 1864
感动是毒
感动是毒 2020-12-04 13:11

I have TextView added Programmatically in to LinearLayout and on some external events I want to decrease bottom margin of that TextView to -10, for that I tried following. <

8条回答
  •  孤街浪徒
    2020-12-04 13:34

    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(50, 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.

提交回复
热议问题