大家好我的recycler查看它没有在第一次运行时完全加载适配器数据,它只会在我滚动recyclelerView后加载。 我认为这个问题与recyclerView的onMeasure或高度相关。我已经尝试了其他方法来解决自定义Layout.Managers的问题,但没有努力。
我的RecyclerView布局:
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_wines"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
我的片段:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initialization(savedInstanceState);
}
protected void initialization(Bundle savedInstanceState) {
super.initialization(savedInstanceState);
mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view_wines);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setHasFixedSize(true);
loadingProgressBar = (ProgressWheel) getView().findViewById(R.id.loading_progressbar);
appbarLayout = (AppBarLayout) getView().findViewById(R.id.appbar);
collapsingToolbar = (CollapsingToolbarLayout) getView().findViewById(R.id.collapsing_toolbar);
tabLayout = (TabLayout) getView().findViewById(R.id.tabs);
backdropTextView = (TextView) getView().findViewById(R.id.backdrop_text_view);
setUpTabLayout();
setUpToolbar();
setUpFragmentCallback();
}
public void onEventMainThread(OnResultEvent resultEvent) {
if (resultEvent!= null ) {
setAdapter(resultEvent);
}
}
private void setAdapter(OnResultEvent resultEvent) {
mRecyclerView.setAdapter(null);
RecyclerViewAdapter recyclerViewAdapter= new RecyclerViewAdapter(getActivity(), resultEvent);
mRecyclerView.setAdapter(recyclerViewAdapter);
RecyclerViewAdapter.notifyDataSetChanged();
}
示例:
答案 0 :(得分:2)
RecyclerView不会包装其内容。为它分配一个常量值,也许你可能会看到整个结果。我曾经遇到过同样的问题。我必须在运行时处理RecyclerView的高度。