gpt4 book ai didi

android - Recyclerview 布局未在 fragment 内正确显示

转载 作者:搜寻专家 更新时间:2023-11-01 09:37:45 26 4
gpt4 key购买 nike

我在 Fragment 中使用 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;
}
}

布局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>

这是我得到的输出。

SS of Output Error

最佳答案

只是移动

app:layout_behavior="@string/appbar_scrolling_view_behavior" 从 reyclerview.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"/>

关于android - Recyclerview 布局未在 fragment 内正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41779852/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com