2016-07-10 45 views
1

嗨,我希望有人能夠從閱讀本網站清除一些混亂我有(4.2節)http://www.vogella.com/tutorials/AndroidFragments/article.html 和一些代碼,我通過YouTube https://www.youtube.com/watch?v=oN2AAhaOBf8Android的工作室多片段於1個活動實施

我的問題可見兩個片段......但你只想一次看到一個片段。在activity_main xml文件中,而不是有

<fragment 
     android:id="@+id/message_fragment" 
     android:name="com.example.android.fragments.MessageListViewFragment" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="top" /> 

    <fragment 
     android:id="@+id/send_fragment" 
     android:name="com.example.android.fragments.SendMessageFragment" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="bottom" /> 

我應該用FrameLayout替換每個片段嗎?或者我只是有一個FrameLayout ...我已經看到兩個,不知道哪一個是正確的。謝謝,我只是想了解..從研究我假設FrameLayout只允許一個片段出現在一次?

回答

1

FrameLayout旨在阻擋屏幕上顯示單個項目的區域。通常情況下,FrameLayout應該用於保存單個子視圖...但是,您可以將多個子項添加到FrameLayout,並通過爲每個子項分配重力來控制其在FrameLayout內的位置。

您可以根據需要使用android:visibility標記並在visible/invisible之間切換。無論佈局如何,這都可以工作。

+0

沒關係,所以在一個片段下1使其可見,而fragment2不可見,那麼它是什麼意思子視圖? – Nameishi

+0

你是說通過改變片段到FrameLayout將不會有所作爲一次看到一個片段? – Nameishi

+0

是的,通過上面的說明,在佔據整個父母的時間只有一個視圖可見。 – Jaydev

相關問題