首页 > 其他 > 详细

布局中的一些小技巧

时间:2017-07-29 10:57:54      阅读:171      评论:0      收藏:0      [点我收藏+]

1:LinearLayput  线性布局

线性布局中设置控件一个居左一个居右,设置一个控件用于占位,设置这个控件 的权重为1,。具体你代码如下

<LinearLayout
    android:background="@color/color_ffe89a"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
        android:layout_gravity="center"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:text="登录"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView
        android:gravity="center_vertical"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:text="注册"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

  2:RelativeLayout   相对布局

相对布局设置一个控件为自包裹,另一个控件占据剩下的所有位置,为另一个控件设置他的宽度的math_parent,代码如下

 <RelativeLayout
        android:background="@color/orange"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/left"
            android:text="左边"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:background="@color/colorf5"
            android:gravity="center"
            android:layout_toRightOf="@+id/left"
            android:text="右边"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </RelativeLayout>

  

 

布局中的一些小技巧

原文:http://www.cnblogs.com/nbls/p/7253972.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!