首页 > 代码库 > android实现综合布局

android实现综合布局

技术分享

要实现这种效果,

  1. LinearLayout的嵌套实现    2.使用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"
        android:paddingLeft="10dp" 
         android:paddingRight="10dp" 
         >
        
    
        
         <EditText 
            android:id="@+id/EditText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/reminder"
        	/>
         
         
         <LinearLayout 
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:orientation="horizontal"
             >
              <EditText 
            android:id="@+id/dates"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
    		android:layout_weight="1"
            
            />
        
         <EditText 
            android:id="@+id/times"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
    		  
            
            />
         
         </LinearLayout>
         
       
         <Button 
             android:id="@+id/button1"
             android:layout_width="96dp"
             android:layout_height="wrap_content"
             android:layout_gravity="right"
             android:text="提交"
             />
    
    </LinearLayout>


  3. <?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" 
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        >
        <EditText 
            android:id="@+id/EditText1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/reminder"
        	/>
        <EditText 
            android:id="@+id/dates"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
    		android:layout_below="@id/EditText1"
    		android:layout_alignParentLeft="true"    
    		android:layout_toLeftOf="@+id/times" 
            
            />
        
         <EditText 
            android:id="@+id/times"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
    		android:layout_below="@+id/EditText1"
    		android:layout_alignParentRight="true"     
            
            />
         
         <Button 
             android:id="@+id/button1"
             android:layout_width="96dp"
             android:layout_height="wrap_content"
             android:layout_below="@id/times"
             android:layout_alignParentRight="true"
             android:text="提交"
             />
        
    
    </RelativeLayout>
    <!--  	android:layout_alignParentLeft="true"    和父控件左对齐
    android:layout_toLeftOf="@+id/times" 在指定组件左边
    android:layout_below="@id/EditText1"   在指定组件下边
     -->

本文出自 “matengbing” 博客,请务必保留此出处http://matengbing.blog.51cto.com/11395502/1880754

android实现综合布局