繁体   English   中英

无法在片段内滚动RecyclerView?

[英]Cannot scroll RecyclerView inside a Fragment?

我在将RecyclerView(在行中使用cardviews)集成到片段中时遇到麻烦。 由于某些原因,我无法滚动名片视图? 有什么建议吗?

这是我的应用程序设计:

在此处输入图片说明

这是我的片段代码:

public class PageFragment2 extends Fragment {
public static final String ARG_PAGE2 = "ARG_PAGE";
private int mPage2;

public static PageFragment2 newInstance(int page) {
    Bundle args = new Bundle();
    args.putInt(ARG_PAGE2, page);
    PageFragment2 fragment = new PageFragment2();
    fragment.setArguments(args);
    return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPage2 = getArguments().getInt(ARG_PAGE2);

    Log.d("MainActivity", "onCreate" + mPage2);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_page2,container,false);

    RecyclerView recList = (RecyclerView) view;
    recList.setHasFixedSize(true);
    LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    recList.setLayoutManager(llm);

    ArrayList<String> names = new ArrayList<>();
    names.add("Georgi Koemdzhiev");
    names.add("Mariya Menova");
    names.add("Simeon Simeonov");
    names.add("Ivan Dqkov");
    names.add("Dymityr Vasilev");
    names.add("Petar Dimov");
    CardAdapter adapter = new CardAdapter(names);

    recList.setAdapter(adapter);
    Log.d("MainActivity","onCreateView" + mPage2);
    return view;
}
}

这是我的片段XML代码:

<android.support.v7.widget.RecyclerView
android:id="@+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
xmlns:android="http://schemas.android.com/apk/res/android"/>

我的activity_main布局:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="koemdzhiev.com.newtablayouttest.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"/>

    <android.support.design.widget.TabLayout
        android:id="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:background="@android:color/white" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main"/>

来自“ Tabbed Activity”模板的Activity(包含包含您的Fragment的ViewPager)使用AppBarLayout。

这个AppBarLayout正在窃取垂直运动,因为它不知道ViewPager中有一个可滚动的嵌套视图(RecyclerView)。 从“活动”的XML文件中删除AppBarLayout(可以将TabLayout和ToolBar移到较高级别)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM