Android-Fragmente: Fragmente innerhalb eines Rahmens oder andere layouts?

Erstelle ich eine Android app jetzt und ich habe einen Rahmen, der Schale enthalten Fragmente. Bis jetzt alles Prima funktioniert, aber ich habe eine Frage, die ich nicht ganz verstehen.

Ich habe ein Frame, welches den gesamten Bildschirm (FrameLayout - sollte ich ein FrameLayout als der main-Frame?) und innerhalb dieses Rahmens gibt es Fragmente, die sich ändern, abhängig von der Benutzer-Interaktion. Diese Fragmente sind in der .xml-Dateien FrameLayouts. Ich Frage mich jetzt, ob Sie können oder sollten FrameLayouts oder Fragmente... erstellt habe ich eine Google Maps frgment das ist ein fragment ideed und das machte mich zu denken.

Also meine Frage ist: Macht es einen Unterschied, oder hat es irgendwelche Auswirkungen auf die Performance oder kann ich das einfach verwenden, was auch immer dient es den Zweck?

Zeigen was ich meine, hier sind einige code-Beispiele:
(Im FrameLayout im inneren des Framelayout sind alle Fragmente setzen)

MainFrame - (activity_main.xml):

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:ignore="MergeRootFrame" >

    <FrameLayout
        android:id = "@+id/mainFrame"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        android:layout_marginBottom = "@dimen/bottom_Main_Tabs">
        </FrameLayout>

    <LinearLayout
        android:layout_width = "match_parent"
        android:layout_height = "@dimen/bottom_Main_Tabs"
        android:layout_gravity = "bottom"
        android:background="@color/grey2"
        >

        <ImageButton
            android:id = "@+id/bottomButton_home"
            android:layout_height = "match_parent"
            android:layout_width = "0dp"
            android:layout_weight = "1.0"
            android:layout_marginLeft = "2dp"
            android:layout_marginRight = "2dp"
            android:background = "@drawable/ic_home_white"
            android:onClick = "openHome"
            />

        [...]

    </LinearLayout>

    <RelativeLayout
        android:id = "@+id/TopBar"
        android:layout_width = "match_parent"
        android:layout_height = "@dimen/top_Bar_Hight"
        android:layout_gravity="top"
        android:background="@color/grey_transparentBy50"
        >

        <ImageView
            android:id= "@+id/TopBarLogo"
            android:layout_width = "@dimen/top_Bar_Hight"
            android:layout_height = "@dimen/top_Bar_Hight"
            android:background="@drawable/ic_launcher"
            />

         [...]

    </RelativeLayout>

</FrameLayout>

Einem Fragment (FrameLayout:)

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/home_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/blue"
    tools:context="com.domain.app.HomeFragment">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:textSize="100sp"
        android:text="Home" />

</FrameLayout>

Anderen Frament (fragment)

<fragment 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:id="@+id/map"
          tools:context="com.domain.app.MapsActivity"
          android:name="com.google.android.gms.maps.MapFragment"
          tools:layout = "@layout/activity_main"
    />

Ist zu hae Probleme mit der GoogleMaps-Implementierung, aber ich habe nicht genug Zeit auf es noch, zu Fragen, hier helfen.

Vielen Dank im Voraus.

John

  • könnten Sie fügen Sie xml-Dateien Inhalte?
  • Frage ist aktualisiert
InformationsquelleAutor JRsz | 2014-09-12
Schreibe einen Kommentar