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?
Ich denke, Ihr Container ist nicht an der richtigen Stelle in der Layout-XML. Könnten Sie bitte die Layoutdatei teilen? –
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