Android-常见的布局

本文详细介绍了Android开发中常见的五种布局方式:线性布局、相对布局、帧布局、表格布局及已过时的绝对布局,并强调了线性布局与相对布局在实际开发中的重要性。

2.android中常见布局

   [1]线性布局   水平  垂直.
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:orientation="vertical"
  5. android:layout_height="match_parent">
  6. <!--@符合就代表R文件-->
  7. <TextView
  8. android:id="@+id/tv_number"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:text="请输入手机号:"
  12. android:textSize="25sp"
  13. />
  14. <EditText
  15. android:id="@+id/et_number"
  16. android:layout_width="match_parent"
  17. android:layout_height="wrap_content"
  18. android:hint="请输入手机号"
  19. />
  20. <Button
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:text="拨打此号码"
  24. />
  25. </LinearLayout>
   [2]相对布局  里面的控件默认都从左上角开始排列
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5. <!--快速格式化代码 ctrl + alt + l-->
  6. <!--@符合就代表R文件-->
  7. <TextView
  8. android:id="@+id/tv_number"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:text="请输入手机号:"
  12. android:textSize="25sp" />
  13. <EditText
  14. android:id="@+id/et_number"
  15. android:layout_width="match_parent"
  16. android:layout_height="wrap_content"
  17. android:layout_below="@id/tv_number"
  18. android:hint="请输入手机号"
  19. />
  20. <Button
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:layout_below="@id/et_number"
  24. android:text="拨打此号码"
  25. />
  26. </RelativeLayout>
   [3]帧布局   分层展示控件.
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5. <!--@符合就代表R文件-->
  6. <TextView
  7. android:id="@+id/tv_number"
  8. android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. android:text="这是视频播放的内容:"
  11. android:textSize="25sp"
  12. />
  13. <Button
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:text="拨打"
  17. android:layout_gravity="center"
  18. />
  19. </FrameLayout>
[4]表格布局  表格由行和列构成 
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5. <!--一个tablerow就代表一行 具体的控件表示列-->
  6. <TableRow
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content">
  9. >
  10. <Button
  11. android:layout_width="match_parent"
  12. android:layout_height="wrap_content"
  13. android:text="1111" />
  14. <Button
  15. android:layout_width="match_parent"
  16. android:layout_height="wrap_content"
  17. android:text="2222" />
  18. </TableRow>
  19. <TableRow
  20. android:layout_width="match_parent"
  21. android:layout_height="wrap_content">
  22. >
  23. <Button
  24. android:layout_width="match_parent"
  25. android:layout_height="wrap_content"
  26. android:text="1111" />
  27. <Button
  28. android:layout_width="match_parent"
  29. android:layout_height="wrap_content"
  30. android:text="2222" />
  31. </TableRow>
  32. </TableLayout>
[5]绝对布局 已经过时 我们开发中很少用 
[6]总结:实际开发中我们使用线性布局和相对布局组合.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值