• Android基础一:Android UI基础容器


    从今天开始,我来分享一些关于Android的一些基础知识,感兴趣一起来学啊!

    大学生交流群:728910358

    目录

    前言

    二、相对布局RelativeLayout

    三、 帧布局FrameLayout


    前言

    从今天开始,我准备分享我最近一年所学到的一些Android基础知识,一方面为了巩固一下我的知识体系,还有一方面是方便各位CSDN有需求的小伙伴学习,接下来让我们一起来学习Android的第一次内容:基础布局容器


    一、线性布局LinearLayout

    线性布局就是从左到右或从上到下按顺序排列的一种布局。下面讲一讲 LinearLayout 的基础属性。

     效果展示

     android:orientation ="vertical"所有子视图纵向摆放

    1. "1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. android:gravity="center" //子视图相对父视图居中显示
    6. android:orientation="vertical"> //所有子视图纵向摆放
    7. <Button
    8. android:layout_width="wrap_content"
    9. android:layout_height="wrap_content"
    10. android:text="普通按钮" />
    11. <Button
    12. android:layout_width="wrap_content"
    13. android:layout_height="wrap_content"
    14. android:text="普通按钮" />
    15. <Button
    16. android:layout_width="wrap_content"
    17. android:layout_height="wrap_content"
    18. android:text="普通按钮" />
    19. <Button
    20. android:layout_width="wrap_content"
    21. android:layout_height="wrap_content"
    22. android:text="普通按钮" />
    23. LinearLayout>

     android:orientation ="horizontal"所有子视图横向摆放

    1. "1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. android:gravity="center" //子视图相对父视图居中显示
    6. android:orientation="horizontal"> //所有子视图横向摆放
    7. ......... 省略
    8. LinearLayout>

    二、相对布局RelativeLayout

    相对于父元素 7 个常用属性

     相对于兄弟元素 4 个常用属性

     相对于兄弟元素的对齐方式

     

     效果演示

     使用 layout_below 使得后面一个组件位于前面一个组件的下方,配合 layout_toRightOf 使得后面一个组件位于前面一个组件的右方。

    1. "1.0" encoding="utf-8"?>
    2. <RelativeLayout
    3. xmlns:android="http://schemas.android.com/apk/res/android"
    4. android:layout_width="match_parent"
    5. android:layout_height="match_parent">
    6. <Button
    7. android:id="@+id/btn1"
    8. android:layout_width="wrap_content"
    9. android:layout_height="wrap_content"
    10. android:text="普通按钮 1" />
    11. <Button
    12. android:id="@+id/btn2"
    13. android:layout_width="wrap_content"
    14. android:layout_height="wrap_content"
    15. android:layout_below="@+id/btn1"
    16. android:layout_toRightOf="@+id/btn1"
    17. android:text="普通按钮 2" />
    18. <Button
    19. android:id="@+id/btn3"
    20. android:layout_width="wrap_content"
    21. android:layout_height="wrap_content"
    22. android:layout_below="@+id/btn2"
    23. android:layout_toRightOf="@+id/btn2"
    24. android:text="普通按钮 3" />
    25. <Button
    26. android:id="@+id/btn4"
    27. android:layout_width="wrap_content"
    28. android:layout_height="wrap_content"
    29. android:layout_below="@+id/btn3"
    30. android:layout_toRightOf="@+id/btn3"
    31. android:text="普通按钮 4" />
    32. RelativeLayout>

    三、 帧布局FrameLayout

    组件的默认位置都是左上角,组件之间可以重叠。像千层饼一样,一层压着一层可以设置上下左右的对齐、水平垂直居中、设置方式与线性布局相似。

    常用属性

    效果演示 

    1. "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. <TextView
    6. android:layout_width="match_parent"
    7. android:layout_height="match_parent"
    8. android:layout_gravity="center"
    9. android:background="@color/purple_200"
    10. android:gravity="center_horizontal"
    11. android:paddingTop="100dp"
    12. android:text="layout_gravity:center"
    13. android:textSize="30dp" />
    14. <TextView
    15. android:layout_width="300dp"
    16. android:layout_height="360dp"
    17. android:layout_gravity="center"
    18. android:background="@color/purple_500" />
    19. <TextView
    20. android:layout_width="240dp"
    21. android:layout_height="240dp"
    22. android:layout_gravity="center"
    23. android:background="@color/purple_700" />
    24. <TextView
    25. android:layout_width="140dp"
    26. android:layout_height="140dp"
    27. android:layout_gravity="center"
    28. android:background="@color/teal_700" />
    29. <TextView
    30. android:layout_width="60dp"
    31. android:layout_height="60dp"
    32. android:layout_gravity="center"
    33. android:background="#ffffff"
    34. android:gravity="center" />
    35. FrameLayout>

     总结

  • 相关阅读:
    RTOS的基本概念与线程基础知识
    @FeignClient注解,fallback和fallbackFactory
    1. MongoDB概览
    2023年初中生古诗文大会初选正在进行中,详细参赛流程和实用建议
    儿童医疗保健生物识别技术市场现状及未来发展趋势分析
    【Android】点击按钮播放音乐,再次点击停止播放
    Pytorch框架学习记录7——卷积层
    5个用于地理空间数据分析的Python包
    [SSD测试 1.1] SSD测试软件哪个好? 8 款固态硬盘软件对比
    ffmpeg 支持用h265编码的rtmp
  • 原文地址:https://blog.csdn.net/m0_58941767/article/details/127726407