当前位置:编程学习 > JAVA >>

Android如何在java代码中设置margin

Android如何在java代码中设置margin,也就是组件与组件之间的间距。


代码中设置:


 

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 
                LayoutParams.FILL_PARENT); 
 params.setMargins(0, 5, 2, 0); 

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT);
 params.setMargins(0, 5, 2, 0);

 

等同于


XML中设置:

<LinearLayout 
                android:id="@+id/wode_03_03" 
                android:layout_width="fill_parent" 
                android:layout_height="<SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif">fill_parent</SPAN>" 
                android:layout_marginRight="2dip" 
                android:layout_marginTop="5dip" > 

 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,