初学Android学到的关于LinearLayout的知识 - Go语言中文社区

初学Android学到的关于LinearLayout的知识


LinearLayout:线性布局的控件,要么横向排布要么纵向排布
无论是哪种排布,都由android:orientation来控制,其中vertical是横向,Horizaontal是纵向
常用的属性:
android:gravity————设置的是控件自身上面的内容位置

android:layout_gravity—–设置控件本身相对于父控件的显示位置

android:layout_weight—– 给控件分配剩余空间

代码举例:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"//宽度填满整个空间
    android:layout_height="match_parent"空间//高度填满
    android:baselineAligned="false"
    android:orientation="vertical">//横向排布
    <Button 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="按钮1"
    />//生成了一个按钮
</LinearLayout>

顺便清楚一下其中的fill_parent,wrap_content和match_parent之间的区别
1)fill_parent是设置一个顶部布局或控件强制性让它布满整个屏幕
2)wrap_content布局指根据视图内部内容自动扩展以适应其大小。
3)match_parent和fill_parent的用法一样

代码举例:
wrap_content:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:orientation="vertical">
    <Botton
    android:id="@+id/btnButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button CJP"/>
 </RelativeLayout>

这里写图片描述

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/juanlansexuehua/article/details/76779966
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-07 21:04:15
  • 阅读 ( 1052 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢