安卓布局Android知识程序员

六大常用布局总结

2017-03-30  本文已影响114人  dayang

LinearLayout

线性布局,有两个方向:垂直与水平,控件的位置控制使用weight与layout_gravity;

RelativeLayout

相对布局,使用多个相对属性控制控件的位置,无法使用layout_gravity

TableLayout

使用<TableRow>标签,标签本身代表一列,标签里面的控件依次各占一列

用TableLayout实现账号输入
  <TableLayout
      android:id="@+i/tableUser"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:gravity="center_vertical"
      android:stretchColumns="0,1">        
      <TableRow
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
      <TextView
          android:id="@+id/tvText"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_weight="1"//
          android:text="用户:"
          android:textSize="20dp" />
      <EditText 
         android:id="@+id/etEditText"                
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="5"
         android:hint="请输入用户名字" />
     </TableRow>
  </TableLayout>
GridLayout

有水平和垂直两个方向;使用columnCount进行一行有多少列的设置,使用columnSpan进行控件的跨列设置,占据一行
使用weightColumns进行列的权重

一些呵呵哒的属性

FrameLayout

帧布局,将控件以一层层帧的形式放置在布局中,像是一叠信件

PercentRelativeLayout

更像是线性布局与相对布局的合体,使用百分比进行控件的大小设置

一些让人呵呵哒的属性

使用步骤
上一篇 下一篇

猜你喜欢

热点阅读