LinearLayoutManager无法parsinggetOrientation()

我有一个RecyclerView实现在一个片段,我试图添加分频器的代码。 我有RecylcerView按预期工作,但LinearLayoutManager无法parsinggetOrientation()函数。

 private RecyclerView mRecyclerView; private RecyclerView.Adapter mAdapter; private RecyclerView.LayoutManager mLayoutManager; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = (View) inflater.inflate(R.layout.fragment_settings, null); getActivity().setTitle("Settings"); mRecyclerView = (RecyclerView) root.findViewById(R.id.recycler_view_settings); mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(getContext()); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new SettingsAdapter(getResources().getStringArray(R.array.setting_list)); mRecyclerView.setAdapter(mAdapter); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), mLayoutManager.getOrientation()); mRecyclerView.addItemDecoration(dividerItemDecoration); return root; } 

Solutions Collecting From Web of "LinearLayoutManager无法parsinggetOrientation()"

更改

 private RecyclerView.LayoutManager mLayoutManager; 

 private LinearLayoutManager mLayoutManager; 

当我创build分隔线时,我遇到了同样的问题。 您可以简单地根据您的RecyclerView的方向自己放置方向, LinearLayoutManager.VERTICALLinearLayoutManager.HORIZONTAL 。 这个对我有用。