首页 > 代码库 > 代码实现Layout android:layout_alignParentRight

代码实现Layout android:layout_alignParentRight

代码实现Layout android:layout_alignParentRight

例如:

     android:id="@+id/account_option" android:layout_width="20px"
     android:layout_height="20px" android:focusable="true"
     android:src="http://www.mamicode.com/@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);

代码实现Layout android:layout_alignParentRight