2014-01-24 17 views
0

這裏是我的xml:XML styleing,把兩個佈局在同一地點

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/FrameLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="bottom" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="10dp" 
     android:orientation="vertical" > 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/surface" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/background" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 
    </LinearLayout> 

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginEnd="0dp" 
    android:layout_gravity="bottom" > 

    <ImageView 
     android:id="@+id/right" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignTop="@+id/down" 
     android:layout_toRightOf="@+id/down" 
     android:src="@drawable/right" /> 

    <ImageView 
     android:id="@+id/left" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignTop="@+id/down" 
     android:layout_toLeftOf="@+id/down" 
     android:src="@drawable/left" /> 

    <ImageView 
     android:id="@+id/up" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentTop="true" 
     android:layout_toLeftOf="@+id/right" 
     android:src="@drawable/up" /> 

    <ImageView 
     android:id="@+id/down" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_below="@+id/up" 
     android:layout_centerHorizontal="true" 
     android:src="@drawable/down" /> 
</RelativeLayout> 

</LinearLayout> 

我想組織的方式是,LinearLayout中「「面」,線性佈局‘背景’將是對屏幕上的相同位置,它們都填滿了除頂部線性佈局和相對佈局之外的所有剩餘位置。並且佈局「表面」將位於佈局「backgrounf」的頂部,我的意思是將在「表面」中顯示的內容將超過「背景」中顯示的內容。

現在是這樣的,它顯示了不diffrnet上的相同點的佈局,divideing所有留室分成兩個相等的部分,每個佈局(surfave和背景)取一個。

我該怎麼做? TNX的幫助:d

回答

0

爲了把佈局上的另一個佈局上面,你有2點不錯的選擇。首先是FrameLayout,超級簡單,只是將視圖疊加在一起。另一種選擇是堅持使用RelativeLayout,你會得到更多的選擇/功能。

如果您選擇RelativeLayout,則需要將兩個佈局設置爲位於相同位置,而不是彼此相鄰。

如果你有一個背景的ImageView,並希望在它的上面一個TextView,你可能會做這樣的事情:

的FrameLayout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:src="@android:drawable/gallery_thumb" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:text="Hello World" /> 
</FrameLayout> 

的RelativeLayout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:src="@android:drawable/gallery_thumb" /> 

    <TextView 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:text="Hello World" /> 
</RelativeLayout> 

(在這個例子中,alignParentXXX不一定是必需的,但我想包含它以明確它們重疊,即使match_parent更改爲wrap_content)

+0

非常感謝!它工作完美 – Omer

相關問題