標題view視圖
android中所有的UI都是通過View和ViewGroup構建的,ViewGroup作為容器裝界面中的控制元件,它可以包含View和ViewGroup,具體關系如下:

注意:android應用的每個界面的根元素必須有且只有一個ViewGroup容器,
標題界面布局的撰寫:
android中用XML檔案控制界面布局,也可以和java代碼分開,使得代碼結構清晰,【res/layout】檔案位置,
Java代碼也可以撰寫代碼,android中所有的布局和控制元件的物件都可以通過new 關鍵字創建出來,
RelativeLayout relativeLayout=new RelativeLayout ( this );
RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams (
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT );
標題布局常用屬性:
android:id
android:layout_width
android:layout_height
android:background
android:layout_margin(外邊距)
android:padding(內邊距)
標題布局方式
1. RelativeLayout相對布局
通過以父控制元件或其他子控制元件為參照物,指定子控制元件的位置
2. LinearLayout線性布局
(1)Android:orientation:
設定該布局中空間的排列順序,
vertical(豎直排列),horizontal(垂直排列)
(2)android:layout_weight:
在布局內設定控制元件權重,屬性值可以直接寫int值
當設定了button控制元件的android:layout_weight屬性時,
控制元件的 android:layout_width屬性值一般設定為0dp才會有權重占比的效果,
3. TableLayout表格布局
表格布局采用行和列來管理控制元件,它不需要宣告有多少行和列,它是通過在tablelayout中添加TableRow布局或控制元件來控制表格行數,可以在Row布局中添加控制元件來控制列數,
布局常用屬性:
android:stretchColumns(可被拉伸的列)
android:shrinkColumns(可被收縮的列)
android:collapseColumns(可被隱藏的列)
控制元件常用屬性:
android:layout_column(該控制元件顯示位置,android:layout_column="0"表示在第一個位置)
android:layout_span(該控制元件占據幾行,默認一行)
4. FrameLayout幀布局
該布局用于在螢屏上創建一塊空白區域,添加到該區域中的每個子控制元件占一幀,這些幀會一個一個疊加在一起,后加入的控制元件會疊加在上一控制元件上層,
屬性:
android:foregroud(設定幀布局容器的前景影像【始終在所有子控制元件之上】)
android:foregroudGravity(設定前景圖的位置)
5.ConstraintLayout約束布局
ConstraintLayout與之前介紹的相比,并不適合使用xml代碼撰寫,但他很適合使用可視化的方式設定空間布局,可視化操作的背后也是xml實作的,只不過代碼是studio自動生成的,
常用屬性
layout_constraintLeft_toLeftOf
layout_constraintLeft_toRightOf
layout_constraintRight_toLeftOf
layout_constraintRight_toRightOf
layout_constraintTop_toTopOf
layout_constraintTop_toBottomOf
layout_constraintBottom_toTopOf
layout_constraintBottom_toBottomOf
layout_constraintBaseline_toBaselineOf
layout_constraintStart_toEndOf
layout_constraintStart_toStartOf
layout_constraintEnd_toStartOf
layout_constraintEnd_toEndOf
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/274760.html
標籤:其他
上一篇:SQLite命令基礎詳解
