六大常用布局總結(jié)

LinearLayout

線性布局,有兩個(gè)方向:垂直與水平,控件的位置控制使用weight與layout_gravity;

RelativeLayout

相對(duì)布局,使用多個(gè)相對(duì)屬性控制控件的位置,無(wú)法使用layout_gravity

TableLayout
  • stretchColumns屬性指定列數(shù),從0開(kāi)始計(jì)數(shù)
  • 一個(gè)控件占據(jù)一行
  • 大多數(shù)屬性跟LinearLayout差不多
  • 列的寬度,通過(guò)weight設(shè)置

使用<TableRow>標(biāo)簽,標(biāo)簽本身代表一列,標(biāo)簽里面的控件依次各占一列

用TableLayout實(shí)現(xiàn)賬號(hào)輸入
  <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"http://
          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="請(qǐng)輸入用戶名字" />
     </TableRow>
  </TableLayout>
GridLayout

有水平和垂直兩個(gè)方向;使用columnCount進(jìn)行一行有多少列的設(shè)置,使用columnSpan進(jìn)行控件的跨列設(shè)置,占據(jù)一行
使用weightColumns進(jìn)行列的權(quán)重

一些呵呵噠的屬性

  • columnCount 設(shè)置一行的最大列數(shù)
  • rowCount 設(shè)置最大的行數(shù)
  • columnSpan 設(shè)置跨列數(shù)
  • rowSpan 設(shè)置跨行數(shù)
  • columnWeight 列的權(quán)重
  • rowWeight 行的權(quán)重
FrameLayout

幀布局,將控件以一層層幀的形式放置在布局中,像是一疊信件

PercentRelativeLayout

更像是線性布局與相對(duì)布局的合體,使用百分比進(jìn)行控件的大小設(shè)置

一些讓人呵呵噠的屬性

  • layout_widthPercent;值為百分比
  • layout_heigthPercent;值為百分比
使用步驟
  • 加上編譯jar包,在gradle文件中compile設(shè)置
    compile 'com.android.support:percent:24.0.0'
  • 在布局文件中進(jìn)行app命名空間設(shè)置
    xmlns:app="http://schemas.android.com/apk/res-auto"
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 看了幾篇文章以及自己寫了一些,關(guān)于布局的問(wèn)題,根據(jù)別人的寫作總結(jié)一下得到 一.基本理論Android六大基本布局分...
    shuaikun閱讀 881評(píng)論 0 4
  • 前言 在進(jìn)行Android開(kāi)發(fā)中,常常需要用到各種布局來(lái)進(jìn)行UI的繪制,今天我們就來(lái)講下Android開(kāi)發(fā)中最常用...
    殘?jiān)掠昙娂?/span>閱讀 701評(píng)論 0 6
  • ¥開(kāi)啟¥ 【iAPP實(shí)現(xiàn)進(jìn)入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開(kāi)一個(gè)線程,因...
    小菜c閱讀 7,335評(píng)論 0 17
  • 一.四大組件: Android四大組件分別為activity、service、content provider、b...
    Ludiwgbet閱讀 1,835評(píng)論 0 39
  • http://www.cocoachina.com/ios/20160630/16890.html
    zhao1zhihui閱讀 135評(píng)論 0 0

友情鏈接更多精彩內(nèi)容