java.lang.IllegalStateException:RecyclerView在片段没有布局管理 [英] java.lang.IllegalStateException: RecyclerView has no LayoutManager in Fragment
问题描述
我是在不断变化的活动变成一个片段的过程中,一旦得到了下面的错误,因为我夸大了RecyclerView。
@覆盖
公共查看onCreateView(LayoutInflater充气,
ViewGroup中的容器,包savedInstanceState){
---->查看rootView = inflater.inflate(R.layout.layout_containing_recyclerview,
集装箱,假);
java.lang.IllegalStateException:RecyclerView没有布局管理
在我改变了我的活动,以一个片段的充气去就好了。
一些进一步的研究表明的删除我所有的子元素的从recyclerview布局帮助解决问题。不过,我不明白为什么这会改变什么,以及为什么它的工作的工作与活动之前。
和
< android.support.v7.widget.RecyclerView的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:ID =@ + ID / my_recycler_view
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:可点击=真
机器人:滚动条=垂直>
< /android.support.v7.widget.RecyclerView>
不工作
< android.support.v7.widget.RecyclerView的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:ID =@ + ID / my_recycler_view
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:可点击=真
机器人:滚动条=垂直>
<查看
机器人:ID =@ + ID / randomview
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =中心/>
< /android.support.v7.widget.RecyclerView>
什么我很想念在这里?
我最终只是膨胀的意见之后是这样的:
@覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,捆绑savedInstanceState){
查看rootView = inflater.inflate(R.layout.fragment_catalog_viewer,集装箱,假);
recyclerView =(RecyclerView)rootView.findViewById(R.id.my_recycler_view);
getLayoutInflater(savedInstanceState).inflate(R.layout.catalog_child,集装箱);
返回rootView;
}
I was in the process of changing an Activity into a Fragment and got the following error as soon as I inflated the RecyclerView.
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
----> View rootView = inflater.inflate(R.layout.layout_containing_recyclerview,
container, false);
java.lang.IllegalStateException: RecyclerView has no LayoutManager
Before I changed my Activity to a Fragment the inflate went just fine.
Some further research showed that removing all my child elements from the recyclerview layout helped solve the problem. However I do not understand why that would change anything and why it did work work with an activity before.
WORKS
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:scrollbars="vertical" >
</android.support.v7.widget.RecyclerView>
DOES NOT WORK
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:scrollbars="vertical" >
<View
android:id="@+id/randomview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</android.support.v7.widget.RecyclerView>
Anything I am missing here?
I ended up just inflating the views afterwards like this:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_catalog_viewer, container, false);
recyclerView = (RecyclerView)rootView.findViewById(R.id.my_recycler_view);
getLayoutInflater(savedInstanceState).inflate(R.layout.catalog_child, container);
return rootView;
}
这篇关于java.lang.IllegalStateException:RecyclerView在片段没有布局管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!