LinearLayout

来源:互联网 发布:新大陆软件怎么样 编辑:程序博客网 时间:2024/05/22 15:48

先来看看api中的基本属性:LinearLayout基本属性
baselineAligned:基准线对齐:听起来很玄乎,因为我们是东方人吗。。。通过例子就清楚了:http://doc.okbase.net/JohnTsai/archive/110444.html
android:baselineAlignedChildIndex:当一个线性布局与另一个布局是按基线对齐的一部分,它可以指定其内容的基线对齐方式。
android:gravity:指定如何在该对象中放置此对象的内容(x/y坐标值)。
android:orientation:设置它内容的对其方向(横向/竖向)。

有两个属性还不是很懂,等以后用到在补上吧!!!

动动手做两个例子也就差不多了吧test

<?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:layout_weight="5"    android:orientation="vertical">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="2"        android:background="@color/blue"></LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="3"        android:orientation="horizontal"        android:weightSum="3">        <LinearLayout            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="2"            android:background="@color/red"            android:orientation="vertical"            android:weightSum="3"            >            <LinearLayout                android:layout_width="match_parent"                android:layout_height="0dp"                android:layout_weight="2"                android:background="@color/green"></LinearLayout>            <LinearLayout                android:layout_width="match_parent"                android:layout_height="0dp"                android:layout_weight="1"></LinearLayout>        </LinearLayout>        <LinearLayout            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"></LinearLayout>    </LinearLayout></LinearLayout>

继续上图
test

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    android:weightSum="8"    tools:context="com.lingzhuo.test1.SecondActivity">    <TextView        android:layout_width="wrap_content"        android:layout_height="0dp"        android:layout_weight="1"        android:text="@string/secondactivity" />    <LinearLayout        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        android:orientation="horizontal">        <Button            android:id="@+id/btnToFirstActivity"            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:background="@color/red"            android:text="@string/backtofirstactivity" />        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="2"            android:background="@color/blue"            android:text="@string/backtofirstactivity" />        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1.5"            android:background="@color/green"            android:text="@string/backtofirstactivity" />    </LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1">        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:text="1" />        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:text="2" />        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:text="3" />        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:text="/" />    </LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1">        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:text="4" />        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:text="5" />        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:text="6" />        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:text="*" />    </LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1">        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:text="7" />        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:text="8" />        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:text="9" />        <Button            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:text="-" />    </LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="2"        android:orientation="horizontal"        android:weightSum="4">        <LinearLayout            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="3">            <LinearLayout                android:layout_width="match_parent"                android:layout_height="match_parent"                android:orientation="vertical"                android:weightSum="2">                <LinearLayout                    android:layout_width="match_parent"                    android:layout_height="0dp"                    android:layout_weight="1"                    android:orientation="horizontal"                    android:weightSum="3">                    <Button                        android:layout_width="0dp"                        android:layout_height="match_parent"                        android:layout_weight="2"                        android:text="0" />                    <Button                        android:layout_width="0dp"                        android:layout_weight="1"                        android:layout_height="match_parent"                        android:text="." />                </LinearLayout>                <Button                    android:layout_width="match_parent"                    android:layout_height="0dp"                    android:layout_weight="1"                    android:text="=" />            </LinearLayout>        </LinearLayout>        <Button            android:layout_width="0dp"            android:layout_weight="1"            android:layout_height="match_parent"            android:text="+" />    </LinearLayout></LinearLayout>
0 0
原创粉丝点击