初学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>

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值