zoukankan      html  css  js  c++  java
  • 【Android快速入门3】布局简介及例子

    目前自学到布局部分,下面演示了不同布局的基本训练,涵盖的内容还是不错的,而且简单易懂,分享给大家。

    1.LinearLayout流式布局

    <?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" >
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="开始"
            />
        <Button 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|left"
            android:text="返回"
            />
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="结束"
            />
        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:weightSum="3"
            >
            <Button 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="new"
                />
            <Button 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:visibility="invisible"
                android:text="newc"
                />
            <Button 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="news"
                />
        </LinearLayout>
    
    </LinearLayout>

    2.RelativeLayout相对布局

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:text="Fight"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:text="L_f"
            />
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:text="R_f"
            />
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            android:text="Run"
            />
        <Button 
            android:id="@+id/bom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="Boom!"
            />
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/bom"
            android:layout_alignBaseline="@+id/bom"
            android:text="左"
            />
         <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/bom"
            android:layout_alignBaseline="@+id/bom"
            android:text="右"
            />
          <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
              android:layout_above="@+id/bom"
              android:layout_centerHorizontal="true"
            android:text="上"
            />
           <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
              android:layout_below="@+id/bom"
              android:layout_centerHorizontal="true"
            android:text="下"
            />
        
    
    </RelativeLayout>

    3.FrameLayout帧布局

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <Button 
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_gravity="center"
            />
        <Button 
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            />
        <Button 
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="center"
            />
    
    </FrameLayout>

    4.其他不常用布局,比如绝对布局,表格布局

    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_x="150dp"
            android:layout_y="160dp"
            android:text="kakka"
            />
    
    </AbsoluteLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:shrinkColumns="0"
        android:collapseColumns="0">
        <TableRow 
            android:layout_height="wrap_content">
            <Button 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="L1,C0"
                    />
            <Button 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="L1,C1"
                    />
            <Button 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="L1,C3"
                    />
            <Button 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="L1,C4"
                    />
            <Button 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="L1,C5"
                    />
        </TableRow>
        <TableRow 
            android:layout_width="wrap_content"
            >
            <Button 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="L2,C0"
                />
            <Button 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="3"
                android:layout_span="2"
                android:text="L2,C1"
                />
        </TableRow>
        
    
    </TableLayout>
  • 相关阅读:
    ZOJ2913Bus Pass(BFS+set)
    HDU1242 Rescue(BFS+优先队列)
    转(havel 算法)
    ZOJ3761(并查集+树的遍历)
    ZOJ3578(Matrix)
    HDU1505
    ZOJ3574(归并排序求逆数对)
    VUE-脚手架搭建
    VUE脚手架搭建
    VUE-node.js
  • 原文地址:https://www.cnblogs.com/pengjunwei/p/3837620.html
Copyright © 2011-2022 走看看