2016-08-18 20 views
-3

有可能爲多個碎片做一個佈局?1佈局多個片段?那可能嗎?

例如..我有一個佈局,我們叫A.XML,我想用它在我的碎片上。有6個片段,每個片段的佈局是相同的。假設在每個片段的佈局中只使用RecycleView

A.XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context=".categoryFragment"> 


    <android.support.v7.widget.RecyclerView 
     android:id="@+id/rvFoodCtg" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:background="#f4f4f4" 
     android:layout_gravity="center" 
     android:layout_weight="1" /> 

</LinearLayout> 

是可能的,如果我想只有A.XML用我所有的6個片段???是的,你們都知道它可以節省內存。

+1

只是延長片段,它要使用相同的佈局,從充氣要使用所有的佈局基本片段片段在其oncreateView。 –

+0

之前問你有沒有試過? –

回答

1

是的,你可以使用相同的Layout多達ActivitiesFragments只要你想