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