Sunday, 8 September 2013

Android set margin of textview programactly

Android set margin of textview programactly

when i try set a margin with this code
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
RelativeLayout.LayoutParams params;
TextView login = (TextView) findViewById(R.id.textView2);
int text_height = login.getHeight();
int text_whidth= login.getWidth();
params = new
RelativeLayout.LayoutParams((int)login.getLayoutParams().WRAP_CONTENT,
(int)login.getLayoutParams().WRAP_CONTENT);
params.setMargins(0, 500, 0, 0);
login.setLayoutParams(params);
}
the app crash on start. how can set margin without crash my app?
thank for help ^^

No comments:

Post a Comment