私のアプリには、画面の下部に固定された2つのタブがあります。これらのタブは、タブに添付された2つのフラグメントの1つが別のフラグメントに置き換えられるたびに、画面の上部に表示されます。ここで下のタブを持つAppCompatActivityは、フラグメントが置き換えられるたびに上のタブに移動します。
は、フラグメントを交換私のコードです:
// 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();
そして、ここでは私のコンテナのレイアウトです:
<?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>
私が主な活動で実装されますインターフェイスを使用してフラグメントを交換してください。これは正しく正しく実行されます。
フラグメントを置き換えた後にタブを下に維持する方法についていくつかのアドバイスを提供できますか?
あなたのコンテナはレイアウトxmlの正しい場所にないと思います。レイアウトファイルを共有していただけますか? –
こんにちはArpit、上記のコンテナコードで質問を編集しました。基本的に、コンテナはViewPagerとTabLayoutを埋め込んだLinearLayoutです。 – Malloc