Android 如何仅显示片段布局

Android 如何仅显示片段布局,android,android-layout,android-studio,android-fragments,Android,Android Layout,Android Studio,Android Fragments,我有一份啤酒单,这是我的主要活动。每当我点击其中一个,我都想显示一个显示啤酒信息的新屏幕 这就是我的列表的外观和创建片段所执行的代码 但是,我没有在新屏幕上显示啤酒的信息,而是同时显示了两种布局: 问题:我怎样才能使只显示片段布局而不显示两者 我的MainActivity布局如下所示: <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="0

我有一份啤酒单,这是我的主要活动。每当我点击其中一个,我都想显示一个显示啤酒信息的新屏幕

这就是我的列表的外观和创建片段所执行的代码

但是,我没有在新屏幕上显示啤酒的信息,而是同时显示了两种布局:

问题:我怎样才能使只显示片段布局而不显示两者

我的MainActivity布局如下所示:

<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>

你需要有两个碎片

BeerListFragment:此片段将具有recyclerview以显示您拥有的啤酒列表。 BeerInfoFragment:此片段将显示单击/选择的啤酒项目的详细信息。
现在,在启动MainActivity时,将BeerListFragment添加到容器中。捕获项目的点击,处理后打开问题中提到的BeerInfoFragment。

您需要两个片段,第一个显示列表,第二个你已经尝试过在片段布局中添加背景色吗?@Pavneet_Singh我会搜索AlbertoMéndez我仍然可以使用列表滚动条滚动我宁愿只显示一个布局,即使我可以隐藏主活动布局否,您将一个触控侦听器添加到片段和长触控侦听器,然后就完成了。如果你只想要其中一个,我想你需要改变你的想法approach@AlbertoM好的,我明白你的意思。实际上我想要两者,因为我希望它能在平板电脑上同时显示列表和所选啤酒的信息,所以我想你的方法是正确的。所以,正如你所说,我可以同时工作和显示两个,但只有一个,因为没有更多的空间?
<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>