我正在將Activity更改爲Fragment,並在我充氣RecyclerView後立即得到以下錯誤。java.lang.IllegalStateException:RecyclerView在片段中沒有LayoutManager
@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沒有佈局管理
之前,我改變了我的活動,以片段的充氣去就好了。
一些進一步的研究表明,從recyclerview佈局中刪除所有我的孩子元素有助於解決問題。然而我不明白爲什麼這會改變什麼,以及爲什麼它的工作與之前的一項活動有關。
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>
不起作用
<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>
什麼我是缺少在這裏?
刪除視圖的工作,但它不是解決整個問題,因爲我們有時真的需要我們放在那裏 – larrytech 2015-09-11 01:39:08