例如:

android:id="@+id/account_option" android:layout_width="20px"

android:layout_height="20px" android:focusable="true"

android:src="@drawable/accountoptionbutton"

android:layout_alignParentRight="true" android:layout_marginRight="25px" />

----------------------------------------------------------------------------------

RelativeLayout rl =    new RelativeLayout(this);

MarginLayoutParams mp = new MarginLayoutParams(20,20);  //item的宽高

mp.setMargins(0, 0, 25, 0);//分别是margin_top那四个属性

LayoutParams lp = new LayoutParams(mp);

lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

Button bt = new Button(this);

bt.setLayoutParams(lp);

rl.addView(bt);

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐