我目前有10項活動。一個是菜單活動,其餘的是類別活動,我目前已經創建了一個名爲menu fragment的片段。我需要創建多少片段?我需要多少片段?
我想從菜單頁面的片段創建到其他頁面。例如,我想在一側顯示菜單頁面,一旦點擊其中一個活動,則顯示另一側的類別。
我只能找到列表視圖和詳細的例子。我是否需要爲每個活動創建片段以及需要創建多少片段。我是否創建一個新的大布局xml.file請指教。
actvitymain.XML
<RelativeLayout 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"
tools:context=".MainActivity">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
></include>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="170dp"
android:id="@+id/linearLayout"
android:weightSum="1"
android:background="#ffffff"
android:layout_below="@+id/tool_bar">
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/museum_icon"
android:background="#ffffff"
android:src="@drawable/museumicon"
android:scaleType="fitXY" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/theatre_icon"
android:background="#00000000"
android:src="@drawable/theatreicon"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/museum_icon"
android:layout_toEndOf="@+id/museum_icon"
android:scaleType="fitXY" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/fooddrink_icon"
android:src="@drawable/foodicon"
android:background="#ffffff"
android:layout_gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/theatre_icon"
android:layout_toEndOf="@+id/theatre_icon"
android:scaleType="fitXY" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_below="@+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/linearLayout2"
android:background="#ffffff">
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/leisure_icon"
android:background="#ffffff"
android:scaleType="fitXY"
android:src="@drawable/leisureicon" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/shopping_icon"
android:background="#00000000"
android:scaleType="fitXY"
android:src="@drawable/shoppingicon"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/leisure_icon"
android:layout_toEndOf="@+id/leisure_icon" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/histroy_icon"
android:src="@drawable/historicalicon"
android:scaleType="fitXY"
android:background="#ffffff"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/shopping_icon"
android:layout_toEndOf="@+id/shopping_icon" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="170dp"
android:id="@+id/linearLayout3"
android:layout_below="@+id/linearLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ffffff"
android:layout_alignParentBottom="true">
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/park_icon"
android:background="#ffffff"
android:scaleType="fitXY"
android:src="@drawable/parkicon" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/familyfun_icon"
android:background="#00000000"
android:scaleType="fitXY"
android:src="@drawable/familyfunicon"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/park_icon"
android:layout_toEndOf="@+id/park_icon" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/travelinfor_icon"
android:src="@drawable/travelicon"
android:scaleType="fitXY"
android:background="#ffffff"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/familyfun_icon"
android:layout_toEndOf="@+id/familyfun_icon" />
</RelativeLayout>
</RelativeLayout>
menufragment.XML
<RelativeLayout 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"
tools:context=".MenuFragment">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
></include>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="170dp"
android:id="@+id/linearLayout"
android:weightSum="1"
android:background="#ffffff"
android:layout_below="@+id/tool_bar">
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/museum_icon"
android:background="#ffffff"
android:src="@drawable/museumicon"
android:scaleType="fitXY" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/theatre_icon"
android:background="#00000000"
android:src="@drawable/theatreicon"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/museum_icon"
android:layout_toEndOf="@+id/museum_icon"
android:scaleType="fitXY" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/fooddrink_icon"
android:src="@drawable/foodicon"
android:background="#ffffff"
android:layout_gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/theatre_icon"
android:layout_toEndOf="@+id/theatre_icon"
android:scaleType="fitXY" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_below="@+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/linearLayout2"
android:background="#ffffff">
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/leisure_icon"
android:background="#ffffff"
android:scaleType="fitXY"
android:src="@drawable/leisureicon" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/shopping_icon"
android:background="#00000000"
android:scaleType="fitXY"
android:src="@drawable/shoppingicon"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/leisure_icon"
android:layout_toEndOf="@+id/leisure_icon" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/histroy_icon"
android:src="@drawable/historicalicon"
android:scaleType="fitXY"
android:background="#ffffff"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/shopping_icon"
android:layout_toEndOf="@+id/shopping_icon" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="170dp"
android:id="@+id/linearLayout3"
android:layout_below="@+id/linearLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ffffff"
android:layout_alignParentBottom="true">
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/park_icon"
android:background="#ffffff"
android:scaleType="fitXY"
android:src="@drawable/parkicon" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/familyfun_icon"
android:background="#00000000"
android:scaleType="fitXY"
android:src="@drawable/familyfunicon"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/park_icon"
android:layout_toEndOf="@+id/park_icon" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/travelinfor_icon"
android:src="@drawable/travelicon"
android:scaleType="fitXY"
android:background="#ffffff"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/familyfun_icon"
android:layout_toEndOf="@+id/familyfun_icon" />
</RelativeLayout>
</RelativeLayout>
museumactivity。 XML
<RelativeLayout 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"
tools:context=".MainActivity">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
></include>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="170dp"
android:id="@+id/linearLayout"
android:weightSum="1"
android:background="#ffffff"
android:layout_below="@+id/tool_bar">
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/museum_icon"
android:background="#ffffff"
android:src="@drawable/museumicon"
android:scaleType="fitXY" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/theatre_icon"
android:background="#00000000"
android:src="@drawable/theatreicon"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/museum_icon"
android:layout_toEndOf="@+id/museum_icon"
android:scaleType="fitXY" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/fooddrink_icon"
android:src="@drawable/foodicon"
android:background="#ffffff"
android:layout_gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/theatre_icon"
android:layout_toEndOf="@+id/theatre_icon"
android:scaleType="fitXY" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_below="@+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/linearLayout2"
android:background="#ffffff">
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/leisure_icon"
android:background="#ffffff"
android:scaleType="fitXY"
android:src="@drawable/leisureicon" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/shopping_icon"
android:background="#00000000"
android:scaleType="fitXY"
android:src="@drawable/shoppingicon"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/leisure_icon"
android:layout_toEndOf="@+id/leisure_icon" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/histroy_icon"
android:src="@drawable/historicalicon"
android:scaleType="fitXY"
android:background="#ffffff"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/shopping_icon"
android:layout_toEndOf="@+id/shopping_icon" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="170dp"
android:id="@+id/linearLayout3"
android:layout_below="@+id/linearLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ffffff"
android:layout_alignParentBottom="true">
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/park_icon"
android:background="#ffffff"
android:scaleType="fitXY"
android:src="@drawable/parkicon" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/familyfun_icon"
android:background="#00000000"
android:scaleType="fitXY"
android:src="@drawable/familyfunicon"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/park_icon"
android:layout_toEndOf="@+id/park_icon" />
<ImageButton
android:layout_width="125dp"
android:layout_height="170dp"
android:id="@+id/travelinfor_icon"
android:src="@drawable/travelicon"
android:scaleType="fitXY"
android:background="#ffffff"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/familyfun_icon"
android:layout_toEndOf="@+id/familyfun_icon" />
</RelativeLayout>
</RelativeLayout>
theatreactivity.XML
<RelativeLayout 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"
tools:context=".MainActivity">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
></include>
<fragment
android:id="@+id/Menufragment"
android:name="com.bradvisor.bradvisor.MenuFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
tools:layout="@layout/fragment_menu" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="260dp"
android:layout_below="@+id/tool_bar"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:weightSum="1"
android:id="@+id/linearLayout4">
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/logo"
android:scaleType="fitCenter"
android:src="@drawable/logofinal"
android:background="#ffffff" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="260dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/linearLayout4" >
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/theatrehead"
android:scaleType="fitXY"
android:src="@drawable/theatrehead"
android:background="#ffffff" />
</LinearLayout>
</RelativeLayout>
這個問題是無法回答的。您可以編寫一個包含0個片段的Android應用程序。或與數百。碎片是一種通用控制器重用和分組UI元素的便捷方式。使用它的正確時間是一個架構決定,取決於你如何編寫應用程序。 –
我想創建片段,因爲我想讓我的應用與平板電腦尺寸兼容。例如,一方面我想用九個圖像按鈕的菜單頁面,一旦用戶點擊一個圖像按鈕,它會在另一個頁面的E.G頁面,菜單頁面和博物館頁面上顯示選定的活動。 –