2012-03-04 70 views
0

我有兩個片段的活性:Android的碎片從查看缺少層次

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:id="@+id/mainlayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <fragment 
     class="com.eyecreate.fragment1" 
     android:id="@+id/fragment1" 
     android:layout_height="match_parent" 
     android:layout_width="269dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentBottom="true" /> 
    <fragment 
     android:id="@+id/fragment2" 
     android:layout_toRightOf="@id/fragment1" 
     android:layout_alignTop="@id/fragment1" 
     android:layout_alignBottom="@id/fragment1" 
     android:layout_alignParentRight="true" 
     class="com.eyecreate.fragment2" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent"></fragment> 
</RelativeLayout> 

片段1不會在屏幕上顯示出來,而不是在層次瀏覽器,但在代碼的情況下仍然有調用onCreate在其上運行。 fragment2出現並佔用整個屏幕。什麼可能導致它剛剛消失?

回答

0

感覺有點笨,我在該片段的onresume過程中調用了 getActivity()。setContentView(fragment2) 。這將導致fragment2成爲唯一出現的一個。

0

layout_height屬性爲fragment2match_parent。這就是它佔據整個屏幕的原因。

我想你想使用LinearLayout而不是RelativeLayoutandroid:orientation對於RelativeLayout沒有意義。

+0

將寬度值和佈局更改爲Linear並未改變事情的顯示方式。 – eyecreate 2012-03-04 21:05:39