Android Recyclerview布局在片段内未正确显示
我在Android Recyclerview布局在片段内未正确显示,android,xml,android-fragments,android-recyclerview,Android,Xml,Android Fragments,Android Recyclerview,我在片段中使用RecyclerView填充项目列表。我能够获得列表,但是显示的布局没有正确显示。该列表仅包含5项,并且仅正确显示4项 public class Old extends Fragment { public Old() {} @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @O
片段中使用RecyclerView
填充项目列表。我能够获得列表,但是显示的布局没有正确显示。该列表仅包含5项,并且仅正确显示4项
public class Old extends Fragment {
public Old() {}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View rootView = inflater.inflate(old_layout, container, false);
RecyclerView mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.setHasFixedSize(true);
DatabaseData data = new DatabaseData(getActivity());
List<OldModel> oldModelList = data.getOldData();
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getActivity());
mRecyclerView.setLayoutManager(linearLayoutManager);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
OldAdapter oldAdapter = new OldAdapter(getActivity(), oldModelList);
mRecyclerView.setAdapter(oldAdapter );
return rootView;
}
}
recyclerview.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/old_layout"
tools:context=".Old">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</RelativeLayout>
快走
app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
从reycerview.xml到include
标记内部
<include layout="@layout/recylerview"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="@+id/appBar"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
布局应该是什么样子?“我觉得它看起来很好。@TobiasBaumeister列表上的第一项显示不正确。清单上只有5项
<include layout="@layout/recylerview"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="@+id/appBar"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>