动态更改TEXTVIEW的边距(左上角)

时间:2015-09-28 09:03:52

标签: android android-activity textview android-view

我已经在相对布局中声明了textview,其中marginleft和marigntop以30dp声明。但我需要在类文件中动态更改那些marginleft和margintop以用于特定的事情。帮助该怎么做。

提前致谢!!!!! 111111

1 个答案:

答案 0 :(得分: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);

我这样做了,效果很好。 也许因为你在-ve中给出了价值,这就是为什么你的代码不起作用的原因。 您只需将此代码放在创建视图引用的位置。