2016-06-20 11 views
0

Meine App hat zwei Registerkarten, die am unteren Rand des Bildschirms bleiben. Diese Registerkarten werden immer dann angezeigt, wenn eines der beiden an die Registerkarten angehängten Fragmente durch ein anderes Fragment ersetzt wird.AppCompatActivity mit Tabs am unteren Rand gelangen zu Tabs nach oben, wenn ein Fragment ersetzt wird

Hier ist mein Code, der das Fragment ersetzen:

// Create fragment and give it an argument for the selected article 
AudioPlayback newFragment = new AudioPlayback(); 

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 

// Replace whatever is in the fragment_container view with this fragment, 
// and add the transaction to the back stack so the user can navigate back 
transaction.replace(R.id.container, newFragment); 
transaction.addToBackStack(null); 
      transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 
// Commit the transaction 
transaction.commit(); 

Und hier ist mein Container Layout:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" android:padding="0dip" 
    android:gravity="center_horizontal" 
    android:id="@+id/container" 
    android:layout_width="match_parent" android:layout_height="match_parent"> 
    <android.support.v4.view.ViewPager 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     /> 
    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="fixed" 
     app:tabIndicatorHeight="3px" 
     app:tabIndicatorColor="@android:color/holo_blue_dark" 
     app:tabGravity="fill" /> 
</LinearLayout> 

Ich ersetze das Fragment über eine Schnittstelle, die in der Haupttätigkeit umgesetzt wird. Dies wird korrekt und erfolgreich durchgeführt.

Können Sie einige Ratschläge geben, wie Sie die Registerkarten nach dem Ersetzen des Fragments nach unten halten können?

+1

Ich denke, Ihr Container ist nicht an der richtigen Stelle in der Layout-XML. Könnten Sie bitte die Layoutdatei teilen? –

+0

Hallo Arpit, ich habe meine Frage mit dem obigen Containercode bearbeitet. Im Grunde ist der Container das LinearLayout, das den ViewPager und TabLayout einbindet. – Malloc

Antwort

0

Dies ist das erwartete Verhalten, dass diese Registerkarten nach oben verschoben werden, sobald Sie ein Fragment in diesem Layout hinzufügen. Wenn Sie eine Fragmentierung vornehmen möchten, bevor die beiden Registerkarten angezeigt werden, nehmen Sie in Ihrem XML-Code die folgenden Änderungen vor.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" android:padding="0dip" 
    android:gravity="center_horizontal" 
    android:layout_width="match_parent" android:layout_height="match_parent"> 
    <FrameLayout android:id="@+id/container" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
    <android.support.v4.view.ViewPager 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     /> 
    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="fixed" 
     app:tabIndicatorHeight="3px" 
     app:tabIndicatorColor="@android:color/holo_blue_dark" 
     app:tabGravity="fill" /> 
</LinearLayout> 
+0

hi, diesmal wird das ersetzende Fragment direkt über dem ersetzten stehen. Wie auch immer, um das Fragment im Vollbild zu zeigen? – Malloc

+0

Starten Sie einfach eine neue Aktivität, die nur dieses Fragment enthält. –

+0

Nicht ganz so, wie ich dem folgen möchte. Danke trotzdem! – Malloc