如何将 RecylerView 与片段布局重叠并使其可单击



我有包含RecyclerView中的单词列表的活动。通过单击"播放"菜单按钮,用户可以启动播放器,该播放器可以语音列表中的所有单词并像简单的音乐播放器一样操作它们。播放器由碎片制成。我想要达到的结果。目前我自己的活动看起来像这样。在这里,我有2个无法解决的问题:1(片段无法与回收商正确重叠。2( 片段按钮不可点击。当我尝试与玩家互动时,第一个列表的项目不断被点击。

为了实现重叠和可点击性,我尝试使用android:alpha和可聚焦属性,但没有带来任何效果。片段的点击侦听器代码已经编写完成。下面我发布必要的活动的xml和java代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar_words"
layout="@layout/layout_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--Container for PlayerFragment-->
<FrameLayout
android:id="@+id/player_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<android.support.v7.widget.RecyclerView
android:id="@+id/words_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>

用于创建玩家片段的活动代码

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.action_player:
initPlayer();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void initPlayer() {
PlayerFragment mPlayerFragment = new PlayerFragment();
FragmentManager mFragmentManager = getSupportFragmentManager();
FragmentTransaction mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.add(R.id.player_container, mPlayerFragment, PLAYER_FRAGMENT);
mFragmentTransaction.commit();
}

尝试以下代码进行回收查看。

<android.support.v7.widget.RecyclerView
android:id="@+id/words_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/player_container"/>

最新更新