Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我需要多少碎片?_Android_Xml_Android Layout_Android Fragments - Fatal编程技术网

Android 我需要多少碎片?

Android 我需要多少碎片?,android,xml,android-layout,android-fragments,Android,Xml,Android Layout,Android Fragments,我目前有10项活动。一个是菜单活动,其余的是类别活动,我目前已经创建了一个称为菜单片段的片段。我还需要创建多少片段 我想创建从菜单页面到其他页面的片段。例如,我希望在单击某个活动后,在一侧显示菜单页面,在另一侧显示类别 我只能找到列表视图和详细示例。我是否需要为每个活动创建片段,以及需要创建多少片段。我是否创建了一个新的大型布局xml.file请告知 actvitymain.XML <RelativeLayout xmlns:android="http://schemas.android.

我目前有10项活动。一个是菜单活动,其余的是类别活动,我目前已经创建了一个称为菜单片段的片段。我还需要创建多少片段

我想创建从菜单页面到其他页面的片段。例如,我希望在单击某个活动后,在一侧显示菜单页面,在另一侧显示类别

我只能找到列表视图和详细示例。我是否需要为每个活动创建片段,以及需要创建多少片段。我是否创建了一个新的大型布局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>

博物馆活动。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> 

根据谷歌文档

片段表示活动中的行为或用户界面的一部分。通过将活动的布局划分为片段,您可以在运行时修改活动的外观,并将这些更改保留在由活动管理的后堆栈中

作为开发人员,如何划分以及何时划分取决于您。如果您认为某个活动太重而无法处理,请将其分解为模块化和可重用的片段。如果多个活动共享相同的UI部分,则将其作为片段拉入


从给出的代码中,我可以建议使用
actvitymain.XML
menuffragment.XML
museumactivity的布局。XML具有几乎相同的UI。因此,您可以将其作为一个片段提取,并将其包含在这3个XML文件中。

这个问题无法回答。您可以编写一个包含0个片段的Android应用程序。或者数百人。片段是一种使用公共控制器重用和分组UI元素的方便方法。使用它的正确时间是一个体系结构决定,取决于您编写应用程序的方式。我想创建片段,因为我想使我的应用程序与平板电脑大小兼容。例如,在一面,我想有一个带有九个图像按钮的菜单页面,一旦用户点击一个图像按钮,它将在另一页上显示所选活动,例如,在另一页上显示菜单页面和博物馆页面。我是否应该创建10个片段并保留10个活动。你觉得呢?我不能给你一个完整的解决方案。这取决于你。阅读编辑后的答案中的我的建议对他们来说并不容易。例如,使菜单活动成为一个片段,这样我将有菜单片段,然后我从菜单容器中加载菜单其他活动。