在两个相对布局之间应用填充

时间:2015-01-25 08:08:25

标签: android

我试图通过在它们之间放置填充来显示两个相对布局 圆角布局将是可见的am附加scrren显示布局是重叠的。所以如何使它们之间的间距

     <?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:background="@drawable/background" >


            <RelativeLayout
                android:id="@+id/relativeLayout1"  android:layout_width="match_parent"
                android:layout_height="fill_parent"   android:paddingTop="22dp"     
                android:paddingLeft="20dp"      android:paddingRight="20dp"   android:paddingBottom="20dp"          
                >


                <RelativeLayout
                    android:id="@+id/create" android:paddingTop="10dp" android:paddingBottom="15dp"
                    android:layout_width="match_parent" android:paddingLeft="10dp" android:paddingRight="10dp"
                    android:layout_height="wrap_content"  android:background="@drawable/rounded_corner"         
                    >


                     <RelativeLayout
                    android:id="@+id/phone"   android:layout_width="match_parent"
                    android:layout_height="wrap_content"    android:layout_below="@+id/last"
                    android:background="#ffffff" >

                    <ImageView
                        android:id="@+id/icon"      android:paddingRight="10dp"
                        android:layout_width="wrap_content"       android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"      android:src="@drawableicon" />

                    <EditText
                        android:id="@+id/Phonenumber"  android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_toRightOf="@+id/icon"
                        android:hint="Enter Phone Number" />
                </RelativeLayout>



           </RelativeLayout>


                <RelativeLayout
                    android:id="@+id/contactAddress"    android:layout_width="match_parent"
                    android:layout_height="wrap_content"  android:layout_below="@+id/create"   android:paddingLeft="10dp"      
                    android:paddingBottom="20dp" android:background="@drawable/rounded_corner"  android:paddingTop="20dp" >



                    <RelativeLayout
                    android:id="@+id/state" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/city"
                    android:background="#ffffff" >

                    <ImageView
                        android:id="@+id/stateicon"  android:paddingRight="10dp"
                        android:layout_width="wrap_content"  android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true" android:src="@drawable/stateicon" />

                    <EditText
                        android:id="@+id/enterstate"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_toRightOf="@+id/stateicon"
                        android:hint="Enter State" />
                </RelativeLayout>





                </RelativeLayout>



               </RelativeLayout> 


            </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"
    android:background="@drawable/background" >


    <RelativeLayout
        android:id="@+id/relativeLayout1"  android:layout_width="match_parent"
        android:layout_height="fill_parent"   android:paddingTop="22dp"     
        android:paddingLeft="20dp"      android:paddingRight="20dp"   android:paddingBottom="20dp"          
        >


        <RelativeLayout
            android:id="@+id/create" android:paddingTop="10dp" android:paddingBottom="15dp"
            android:layout_width="match_parent" android:paddingLeft="10dp" android:paddingRight="10dp"
            android:layout_height="wrap_content"  android:background="@drawable/rounded_corner"         
            >


             <RelativeLayout
            android:id="@+id/phone"   android:layout_width="match_parent"
            android:layout_height="wrap_content"    android:layout_below="@+id/last"
            android:background="#ffffff" >

            <ImageView
                android:id="@+id/icon"      android:paddingRight="10dp"
                android:layout_width="wrap_content"       android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"      android:src="@drawableicon" />

            <EditText
                android:id="@+id/Phonenumber"  android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/icon"
                android:hint="Enter Phone Number" />
        </RelativeLayout>



   </RelativeLayout>


        <RelativeLayout
            android:id="@+id/contactAddress"    android:layout_width="match_parent"
            android:layout_height="wrap_content"  android:layout_below="@+id/create"   android:paddingLeft="10dp"      
            android:paddingBottom="20dp" android:background="@drawable/rounded_corner"  android:paddingTop="20dp" >



            <RelativeLayout
            android:id="@+id/state" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/city"
            android:background="#ffffff" >

            <ImageView
                android:id="@+id/stateicon"  android:paddingRight="10dp"
                android:layout_width="wrap_content"  android:layout_height="wrap_content"
                android:layout_alignParentLeft="true" android:src="@drawable/stateicon" />

            <EditText
                android:id="@+id/enterstate"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/stateicon"
                android:hint="Enter State" />
        </RelativeLayout>





        </RelativeLayout>



       </RelativeLayout> 






    </RelativeLayout>

1 个答案:

答案 0 :(得分:0)

这个XML完全搞砸了。

首先,您应该正确缩进代码,使其更具可读性。这是一种很好的做法,如果你想在(严肃的)团队中工作,这是必要的。

其次,你有太多的相对布局。 RelativeLayout是最重的&#34;要呈现的布局。如果你想走这条路线,这远非好(灾难性的,真的),至少使用FrameLayout来封装statephone相对布局。然后在内部元素上尝试边距,如果填充不起作用。

第三,如果你想做得体面,就要避免这种做法。为一个布局制作背景......圆角和所有。