国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android布局居中的幾種做法

2019-12-12 05:14:04
字體:
來源:轉載
供稿:網友

Android的布局文件中,如果想讓一個組件(布局或View)居中顯示在另一個布局(組件)中,可以由這么幾種做法:

  1. android:layout_gravity
  2. android:gravity
  3. android:layout_centerInParent

layout_gravity

android:layout_gravity ,用來指定當前組件(布局或View)在父組件(布局)中的位置,父布局應該是LinearLayout或者它的后裔。

layout_gravity取值可能是:

  1. top
  2. bottom
  3. left
  4. right
  5. center_vertical
  6. fill_vertical
  7. center_horizontal
  8. fill_horizontal
  9. center
  10. fill
  11. clip_vertical
  12. clip_horizontal
  13. start
  14. end

與居中相關的已經粗體標注出來。各種取值的具體含義,參看:

https://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html 。

gravity

android:gravity 是View的屬性,用來指定View的子組件在View中的位置。適用于所有的View和布局。它的取值有很多,具體參見: https://developer.android.com/reference/android/view/Gravity.html 。

與居中相關的取值:

  1. center
  2. center_horizontal
  3. center_vertical

當你設定一個布局 android:gravity="center" 時,它的子組件就會居中。當你設定一個View android:gravity="center" 時,它的內容會居中,以TextView為例,文字會居中。

layout_centerInParent

android:layout_centerInParent 是RelativeLayout的布局屬性,如果一個組件(布局或View)的父布局是RelativeLayout,就可以使用這個屬性來居中。其取值為 true 或 false 。

與其類似的還有:

  1. android:layout_centerHorizontal
  2. android:layout_centerVertical

具體含義和用法參看: https://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html 。

以上就是對Android 布局居中的幾種方法整理,后續(xù)繼續(xù)補充相關資料,謝謝大家對本站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 平和县| 剑河县| 临安市| 大兴区| 溧阳市| 奈曼旗| 胶州市| 瑞丽市| 新河县| 聂拉木县| 新宁县| 油尖旺区| 扶风县| 中超| 普安县| 虎林市| 白山市| 郸城县| 辉南县| 庄河市| 扶余县| 化隆| 新巴尔虎左旗| 义乌市| 尼玛县| 长兴县| 孙吴县| 板桥市| 蒙自县| 威远县| 兴宁市| 比如县| 仪陇县| 绵阳市| 马尔康县| 苗栗市| 景德镇市| 石屏县| 信阳市| 云林县| 上思县|