在我的布局xml中,如果我执行类似android:layout_marginTop="10px"
的操作,我怎样才能在java中执行相同的操作?
答案 0 :(得分:0)
试试这个:
RelativeLayout rel=new RelativeLayout(this);
mWidth=getWindowManager().getDefaultDisplay().getWidth();
RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(mWidth,mHeight);
Button mBtn=(Button) findViewById(R.id.xBtn);
params=new RelativeLayout.LayoutParams(mWidth, mHeight);
params.setMargins(int left, int top, int right, int bottom);
mBtn.setLayoutParams(params);