2
Fragment
の中にRecyclerView
を使用してアイテムのリストを設定しています。私はリストを表示することができますが、表示されているレイアウトが正しく表示されていません。リストには5つのアイテムしか含まれておらず、4つのアイテムが正しく表示されています。フラグメント内にRecyclerviewのレイアウトが正しく表示されない
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;
}
}
レイアウトXMLのold_layout.xml
<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=".Old">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
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.AppBarLayout>
<include layout="@layout/recylerview"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="@+id/appBar"/>
//also tried android:layout_below="@+id/toolbar"
</android.support.design.widget.CoordinatorLayout>
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>
これは私が取得しています出力されます。
レイアウトはどのように見えますか?それは私にとっては完璧に見えます。 –
@TobiasBaumeisterリストの最初の項目が正しく表示されていません。リストには5つのアイテムしかありません – Jah