Android 无法在片段内滚动RecyclerView?

Android 无法在片段内滚动RecyclerView?,android,android-fragments,android-recyclerview,Android,Android Fragments,Android Recyclerview,我在片段中集成RecyclerView(对行使用CardView)时遇到问题。由于某种原因,我无法滚动卡片视图?请问,有什么建议吗 这是我的应用程序设计: 这是我的片段代码: public class PageFragment2 extends Fragment { public static final String ARG_PAGE2 = "ARG_PAGE"; private int mPage2; public static PageFragment2 newInstance(int

我在片段中集成RecyclerView(对行使用CardView)时遇到问题。由于某种原因,我无法滚动卡片视图?请问,有什么建议吗

这是我的应用程序设计:

这是我的片段代码:

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;
}
}
公共类PageFragment2扩展了片段{
公共静态最终字符串ARG_PAGE2=“ARG_PAGE”;
私人int mPage2;
公共静态页面碎片2新实例(int页){
Bundle args=新Bundle();
args.putInt(ARG_第2页,第2页);
PageFragment2 fragment=新的PageFragment2();
fragment.setArguments(args);
返回片段;
}
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mPage2=getArguments().getInt(ARG_PAGE2);
日志d(“主活动”、“onCreate”+mPage2);
}
@凌驾
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
视图=充气机。充气(R.layout.fragment_page2,容器,错误);
RecyclerView重新列表=(RecyclerView)视图;
recList.setHasFixedSize(真);
LinearLayoutManager llm=新的LinearLayoutManager(getActivity());
重新登录setLayoutManager(llm);
ArrayList name=新的ArrayList();
名称。添加(“Georgi Koemdzhiev”);
姓名。添加(“Mariya Menova”);
名称。添加(“Simeon Simeonov”);
名称。添加(“Ivan Dqkov”);
名称。添加(“Dymityr Vasilev”);
名称。添加(“Petar Dimov”);
CardAdapter=新的CardAdapter(名称);
recList.setAdapter(适配器);
Log.d(“MainActivity”、“onCreateView”+mPage2);
返回视图;
}
}
这是我的片段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"/>

我的活动单元主布局:

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

来自“选项卡式活动”模板的活动使用AppBarLayout,该模板包含包含片段的ViewPager

这个AppBarLayout窃取了垂直移动,因为它不知道ViewPager中有一个可滚动的嵌套视图(RecyclerView)。从活动的XML文件中删除AppBarLayout(您可以将TableAyout和工具栏移到更高级别)。

包含包含片段的ViewPager的“选项卡式活动”模板中的活动使用AppBarLayout


这个AppBarLayout窃取了垂直移动,因为它不知道ViewPager中有一个可滚动的嵌套视图(RecyclerView)。从活动的XML文件中删除AppBarLayout(您可以将TableLayout和工具栏移到更高级别)。

为什么需要relativeLayout?摆脱it@injecteer我不知道我为什么加上它。我删除了它,但问题仍然存在。我用更改更新了我的问题。由于某种原因,请尝试addind
llm.setorination(水平)
@injecteer,我正在滚动。但是,我想垂直滚动。我确实试着把它设置成垂直,但它仍然不起作用……这有点小错误。不要像索里亚诺夫的回答那样用
AppBarLayout
来包装你的内容区域:)为什么你需要一个relativeLayout?摆脱it@injecteer我不知道我为什么加上它。我删除了它,但问题仍然存在。我用更改更新了我的问题。由于某种原因,请尝试addind
llm.setorination(水平)
@injecteer,我正在滚动。但是,我想垂直滚动。我确实试着把它设置成垂直,但它仍然不起作用……这有点小错误。不要用
AppBarLayout
作为索里亚诺夫的答案来包装你的内容区域:)谢谢你的回答。然而,我不太清楚你的建议是什么。我还包括了我的活动的主要xml代码。您能告诉我需要更改什么吗?:)没关系,我刚刚将我的TableAyout和ViewPager包装在AppBarLayout的LinierView中,现在可以正常工作了。谢谢谢谢你的回答。然而,我不太清楚你的建议是什么。我还包括了我的活动的主要xml代码。您能告诉我需要更改什么吗?:)没关系,我刚刚将我的TableAyout和ViewPager包装在AppBarLayout的LinierView中,现在可以正常工作了。谢谢