Android橫豎屏自適應ScrollView及Button組居中布局


    界面如下:

   

    可以根據需要進行擴展,layout代碼如下:

   

<? xml version="1.0" encoding="utf-8" ?>
< ScrollView  xmlns:android ="http://schemas.android.com/apk/res/android"
    android:layout_width
="fill_parent"
    android:layout_height
="fill_parent"   >

     < LinearLayout
        
android:layout_width ="fill_parent"
        android:layout_height
="wrap_content"
        android:gravity
="center"
        android:orientation
="vertical"   >

         < RelativeLayout
            
android:layout_width ="wrap_content"
            android:layout_height
="wrap_content"
            android:paddingTop
="20dp"
            android:paddingBottom
="20dp"   >

             < Button
                
android:id ="@+id/btn1"
                android:layout_width
="wrap_content"
                android:layout_height
="wrap_content"
                android:text
="測試按鈕01"   />

             < Button
                
android:layout_width ="wrap_content"
                android:layout_height
="wrap_content"
                android:layout_marginLeft
="50dp"
                android:layout_toRightOf
="@id/btn1"
                android:text
="測試按鈕02"   />
         </ RelativeLayout >

         < RelativeLayout
            
android:layout_width ="wrap_content"
            android:layout_height
="wrap_content"
            android:paddingBottom
="20dp"   >

             < Button
                
android:id ="@+id/btn2"
                android:layout_width
="wrap_content"
                android:layout_height
="wrap_content"
                android:text
="測試按鈕03"   />

             < Button
                
android:layout_width ="wrap_content"
                android:layout_height
="wrap_content"
                android:layout_marginLeft
="50dp"
                android:layout_toRightOf
="@id/btn2"
                android:text
="測試按鈕04"   />
         </ RelativeLayout >

         < RelativeLayout
            
android:layout_width ="wrap_content"
            android:layout_height
="wrap_content"
            android:paddingBottom
="20dp"   >

             < Button
                
android:id ="@+id/btn3"
                android:layout_width
="wrap_content"
                android:layout_height
="wrap_content"
                android:text
="測試按鈕05"   />

             < Button
                
android:layout_width ="wrap_content"
                android:layout_height
="wrap_content"
                android:layout_marginLeft
="50dp"
                android:layout_toRightOf
="@id/btn3"
                android:text
="測試按鈕06"   />
         </ RelativeLayout >

         < RelativeLayout
            
android:layout_width ="wrap_content"
            android:layout_height
="wrap_content"
            android:paddingBottom
="20dp"   >

             < Button
                
android:id ="@+id/btn4"
                android:layout_width
="wrap_content"
                android:layout_height
="wrap_content"
                android:text
="測試按鈕07"   />

             < Button
                
android:layout_width ="wrap_content"
                android:layout_height
="wrap_content"
                android:layout_marginLeft
="50dp"
                android:layout_toRightOf
="@id/btn4"
                android:text
="測試按鈕08"   />
         </ RelativeLayout >

         < RelativeLayout
            
android:layout_width ="wrap_content"
            android:layout_height
="wrap_content"
            android:paddingBottom
="20dp"   >

             < Button
                
android:id ="@+id/btn5"
                android:layout_width
="wrap_content"
                android:layout_height
="wrap_content"
                android:text
="測試按鈕09"   />

             < Button
                
android:layout_width ="wrap_content"
                android:layout_height
="wrap_content"
                android:layout_marginLeft
="50dp"
                android:layout_toRightOf
="@id/btn5"
                android:text
="測試按鈕10"   />
         </ RelativeLayout >

         < RelativeLayout
            
android:layout_width ="wrap_content"
            android:layout_height
="wrap_content"
            android:paddingBottom
="20dp"   >

             < Button
                
android:id ="@+id/btn6"
                android:layout_width
="wrap_content"
                android:layout_height
="wrap_content"
                android:text
="測試按鈕11"   />

             < Button
                
android:layout_width ="wrap_content"
                android:layout_height
="wrap_content"
                android:layout_marginLeft
="50dp"
                android:layout_toRightOf
="@id/btn6"
                android:text
="測試按鈕12"   />
         </ RelativeLayout >

         < RelativeLayout
            
android:layout_width ="wrap_content"
            android:layout_height
="wrap_content"
            android:paddingBottom
="20dp"   >

             < Button
                
android:id ="@+id/btn7"
                android:layout_width
="wrap_content"
                android:layout_height
="wrap_content"
                android:text
="測試按鈕13"   />

             < Button
                
android:layout_width ="wrap_content"
                android:layout_height
="wrap_content"
                android:layout_marginLeft
="50dp"
                android:layout_toRightOf
="@id/btn7"
                android:text
="測試按鈕14"   />
         </ RelativeLayout >
     </ LinearLayout >

</ ScrollView >

 

    轉載請注明出處,網址:http://www.cnblogs.com/waterfrost


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM