Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Can';t设置回收视图_Android_Android Appcompat_Android Recyclerview - Fatal编程技术网

Android Can';t设置回收视图

Android Can';t设置回收视图,android,android-appcompat,android-recyclerview,Android,Android Appcompat,Android Recyclerview,好的,在过去的4-5个小时里,我一直在努力让它工作,但没有成功 我从sdk/extras/android/support中添加了appcompat作为库和RecyclerView 这里没有错误: 这就是我的依赖项和LIB的样子: 我可以导入android.support.v7.widget.RecyclerView;到我的课堂上,并使用它们。我可以制作自己的适配器,并且没有错误 但是我不能在xml中使用。我总是很紧张 The following classes could not be i

好的,在过去的4-5个小时里,我一直在努力让它工作,但没有成功

我从sdk/extras/android/support中添加了appcompat作为库和RecyclerView

这里没有错误:

这就是我的依赖项和LIB的样子:

我可以导入android.support.v7.widget.RecyclerView;到我的课堂上,并使用它们。我可以制作自己的适配器,并且没有错误

但是我不能在xml中使用。我总是很紧张

The following classes could not be instantiated:
- android.support.v7.widget.RecyclerView (Open Class, Show Error Log)
如果我尝试运行代码,则会出现以下错误:


我如何解决这个问题?我曾尝试在Android Studio中使用RecyclerView,但也出现了相同的错误。

您可以在下面尝试:

在包含android.support.v7.widget.RecyclerView的视图xml中:

android:layout_width="match_parent"
android:layout_height="match_parent"
并确保其父容器不是包装内容

在守则中:

private LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(getActivity());
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);

RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.cardsList);
recyclerView.setLayoutManager(mLayoutManager);

因为你没有发布你的代码。仅凭猜测,我认为如果你给你的RecyclerView match_父容器,而它的父容器使用wrap_内容,这会引起混乱——可能是测量问题。是的,的确如此。最后,我只需要添加这些代码行,在这里发布问题半分钟后我就解决了它。谢谢你的帮助。