Android UI布局之LinearLayout

<span style="font-size:18px;">课程大纲:1、布局概述</span>
<span style="font-size:18px;">布局为UI提供了一个可视化的结构,比如对于一个activity或者app widget的UI。</span>
<span style="font-size:18px;">你可以用两种方式声明布局:<span style="font-family: Arial, Helvetica, sans-serif;">(1)在XML中声明UI元素(2)在运行实例化布局元素</span></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size:18px;">线性布局,按照水平或垂直方向布局组件android:orientation="horizontal"</span></span>
<span style="font-size:18px;">用来设置排列方向;horizontal是水平排列,vertical是垂直排列。</span>
在UI的Linearlayout布局中,其中android:layout_gravity和android:gravity的使用区别:

android:gravity:这个是针对控件里的元素来说的,用来控制元素在该控件里显示的位置。

android:layout_gravity:这个是针对控件本身而言,用来控制该控件在包含该控件的父控件中的位置


<span style="color:#660000;">该代码写在layout的liner_layout.xml(自己建立)文件中</span>
<span style="color:#660000;"><span style="font-size:14px;"><span style="color:#009900;"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="red"
        android:layout_weight="1"
        android:background="#ff0000"
        />
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="green"
        android:layout_weight="1"
        android:background="#00ff00"
        />
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="blue"
        android:layout_weight="1"
        android:background="#0000ff"
        />
    
    

</LinearLayout></span>
</span></span>


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值