线性布局Linerlayout-计算器布局实现

来源:互联网 发布:aynak.apk软件下载 编辑:程序博客网 时间:2024/05/21 17:44
今天把线性布局这个基本的概念和使用技巧又学习了一下。
有个技巧就是:
 把整个界面划分成几块,然后这几块怎么摆放就是很easy的事情了。
同时要理解 wrap_content   match_parent 这2个属性的含义。
 match_parent :就是填充满父控件,父控件有多宽,多高,那它就有多宽多高。 
 wrap_content : 就是包裹内部的文字或者图片。 没有多余的空间,直接包裹住 
 
<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" >    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <EditText            android:id="@+id/msg"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />    </LinearLayout>    <!-- Linerlayout 可以嵌套使用 -->    <!-- 第一列 -->    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="mc" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="m+" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="m-" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="mr" />    </LinearLayout>    <!-- 第2列 -->    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="C" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="+/-" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="/" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="*" />    </LinearLayout>    <!-- 第3列 -->    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="7" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="8" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="9" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="*" />    </LinearLayout>    <!-- 第4列 -->    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="4" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="5" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="6" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="-" />    </LinearLayout>    <!-- 第5列 -->    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:orientation="vertical" >            <LinearLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:orientation="horizontal" >                <Button                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:text="1" />                <Button                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:text="2" />                <Button                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:text="3" />            </LinearLayout>            <LinearLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:orientation="horizontal" >                <Button                    android:layout_width="0px"                    android:layout_height="wrap_content"                    android:layout_weight="2"                    android:text="0" />                <Button                    android:layout_width="0px"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:text="." />            </LinearLayout>        </LinearLayout>        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:layout_weight="1"            android:orientation="horizontal" >            <Button                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_weight="1"                android:text="=" />        </LinearLayout>    </LinearLayout></LinearLayout>



0 0