私は主な活動であるビールのリストを持っていますMainActivity。その中の1つをクリックするたびに、ビール情報を示す新しい画面を表示したい。フラグメントのレイアウトのみを表示する方法
これは、私のリストがどのように見えるのか、私のフラグメントを作るために実行されるコードです。
@Override
public void onClick(View view) {
// Data to send to fragment
Beer beer = displayedList.get(getAdapterPosition());
Bundle bundle = new Bundle();
bundle.putParcelable("Beer", beer);
bundle.putParcelableArrayList("BeerList", (ArrayList<? extends Parcelable>) beerList);
// Begin the transaction
FragmentTransaction ft = context.getSupportFragmentManager().beginTransaction();
// Replace the contents of the container with the new fragment
BeerInfoFragment beerInfoFragment = new BeerInfoFragment();
beerInfoFragment.setArguments(bundle);
ft.replace(R.id.frame_layout, beerInfoFragment);
// or ft.add(R.id.your_placeholder, new FooFragment());
// Complete the changes added above
ft.commit();
}
}
しかし、代わりに新しい画面上のビールの情報を表示するので、私は同時に両方のレイアウトを得た:
はQUESTION:どのようにすることができます両方の代わりにフラグメントレイアウトを表示するだけですか?
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
2つのフラグメントが必要です。最初はリストを表示し、もう1つはすでに表示されています –
フラグメントレイアウトに背景色を追加しようとしましたか? –
@Pavneet_Singhそれについて検索します AlbertoMéndezリストスクロールバーを使用してスクロールすることができますMainActivityレイアウトを非表示にしてもレイアウトを表示したい – deko