• Android学习第五天


    详解3种基本布局

    LinearLayout又称作线性布局,这个布局会将它所包含的控件在线性方向上依次排列。

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 1" />
    <Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 2" />
    <Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 3" />
    </LinearLayout>

     LinearLayout横向排列的效果。

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    ...
    </LinearLayout>

    LinearLayout使用ayout_gravity属性对齐的效果。
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:text="Button 1" />
    <Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:text="Button 2" />
    <Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:text="Button 3" />
    </LinearLayout>

    RelativeLayout又称作相对布局,它可以通过相对定位的方式让控件出现在布局的任何位置。
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" …>
    <Button …
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Button 1" />
    <Button …
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="Button 2" />
    <Button …
    android:layout_centerInParent="true"
    android:text="Button 3" />
    <Button …
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="Button 4" />
    <Button …
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="Button 5" />
    </RelativeLayout>

    除了相对于父布局定位之外,RelativeLayout还允许相对于控件进行定位。
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" ...>
    <Button ...
    android:layout_centerInParent="true"
    android:text="Button 3" />
    <Button ...
    android:layout_above="@id/button3"
    android:layout_toLeftOf="@id/button3"
    android:text="Button 1" />
    <Button ...
    android:layout_above="@id/button3"
    android:layout_toRightOf="@id/button3"
    android:text="Button 2" />
    <Button ...
    android:layout_below="@id/button3"
    android:layout_toLeftOf="@id/button3"
    android:text="Button 4" />
    <Button ...
    android:layout_below="@id/button3"
    android:layout_toRightOf="@id/button3"
    android:text="Button 5" />
    </RelativeLayout>

  • 相关阅读:
    搜广推04-信息检索任务&数据集&LeadBoard&评价指标
    搜广推&NLP03-顶会track记录
    搜广推02-DeepMatch 模型总结[SIGIR2019 tutorial]
    搜广推01-信息检索领域大佬总结
    计算机基础01-终端命令行、VIM、git、CICD
    【python】彼岸图网4K壁纸批量爬虫共1.48G(多线程/多进程)
    【python】不到500行代码实现flappybird小游戏
    解决pyinstaller打包程序太大的问题
    解决pipenv install报错FileNotFoundError: [Errno 2] No such file or directory: ‘d:\miniconda3\Lib\venv
    【python】如何将matplotlib的标题置于图片下方
  • 原文地址:https://www.cnblogs.com/yongyuandishen/p/14865984.html
Copyright © 2020-2023  润新知