• Android -- UI布局管理,相对布局,线性布局,表格布局,绝对布局,帧布局


    1. 相对布局

    <RelativeLayout 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"
        tools:context=".MainActivity" >
    
        <TextView
            android:id="@+id/tv_phone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="请输入手机号" />
    
        <EditText
            android:id="@+id/et_phone"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_phone"
            android:hint="手机号" />
    
        <TextView
            android:id="@+id/tv_content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/et_phone"
            android:text="请输入短信内容" />
    
        <EditText
            android:id="@+id/et_content"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_content"
            android:hint="短信内容"
            android:inputType="textMultiLine"
            android:minLines="5" />
    
        <Button
            android:layout_alignParentRight="true"
            android:layout_below="@id/et_content"
            android:text="发送短信"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
    </RelativeLayout>

    2.  线性布局

    <?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" >
        
        <RelativeLayout	android:layout_width="match_parent"
        	android:layout_height="wrap_content" >    	
            <TextView
                android:id="@+id/tv1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="XXXXXXX"
                android:textSize="20sp" />
            <TextView
                android:id="@+id/tv2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tv1"
                android:text="YYYYYYYYYYY"
                android:textSize="15sp" />
            <CheckBox         
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerInParent="true" 
                />        
        </RelativeLayout>
        
        <View
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:background="#88000000" 
            />
        
        <RelativeLayout	android:layout_width="match_parent"
        	android:layout_height="wrap_content" >    	
            <TextView
                android:id="@+id/tv12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="XXXXXXX"
                android:textSize="20sp" />
            <TextView
                android:id="@+id/tv22"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tv12"
                android:text="YYYYYYYYYYY"
                android:textSize="15sp" />
            <CheckBox         
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerInParent="true" 
                />        
        </RelativeLayout>
        
        <View
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:background="#88000000" 
            />
    
    </LinearLayout>
    

    3. 表格布局

    <?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" >
    
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    		
    		<!--width=0,设置weight 权重, 显示比例-->
            <TextView
                android:gravity="center"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="用户名" />
    
            <EditText
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="2" />
        </TableRow>
    
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <TextView
                android:gravity="center"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="密码" />
    
            <EditText
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:inputType="textPassword" />
        </TableRow>
    
    </TableLayout>

    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:id="@+id/button2"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_x="62dp"
            android:layout_y="318dp"
            android:text="Button" />
    
        <ToggleButton
            android:id="@+id/toggleButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_x="59dp"
            android:layout_y="46dp"
            android:text="ToggleButton" />
    
        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_x="39dp"
            android:layout_y="134dp"
            android:text="CheckBox" />
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_x="237dp"
            android:layout_y="61dp"
            android:text="Button" />
    
    </AbsoluteLayout>

    5.帧布局

    几层控件跌在一起, 可以控制显示那一层,应用场景: 播放器暂停时的暂停图标。

    <?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" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#88000000" >
        </LinearLayout>
    
        <ImageView
            android:visibility="visible"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="center"
            android:src="@drawable/ic_launcher" />
    
    </FrameLayout>




     

  • 相关阅读:
    简单的Servlet结合Jsp实现请求和响应以及对doGet和doPost的浅析
    My1stServlet
    Myeclipse发布第一个jsp页面及web project部署到tomcat上的几种方法
    java中循环的不同终止方式
    Mybatis学习笔记
    python 进程间的数据交互
    python 进程
    python 队列
    python 多线程
    python paramiko 向linux执行命令和发送接收文件
  • 原文地址:https://www.cnblogs.com/xj626852095/p/3647989.html
Copyright © 2020-2023  润新知