我有一个RecyclerView
片段实现,我试图在代码中添加分隔符.我RecylcerView
按预期工作,但LinearLayoutManager
无法解决getOrientation()
功能.
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; }
小智.. 17
更改
private RecyclerView.LayoutManager mLayoutManager;
至
private LinearLayoutManager mLayoutManager;
Zin Win Htet.. 8
创建分隔线时遇到相同的问题。您可以简单地自己输入方向,LinearLayoutManager.VERTICAL
或者LinearLayoutManager.HORIZONTAL
根据您的方向RecyclerView
。这个对我有用。
更改
private RecyclerView.LayoutManager mLayoutManager;
至
private LinearLayoutManager mLayoutManager;
创建分隔线时遇到相同的问题。您可以简单地自己输入方向,LinearLayoutManager.VERTICAL
或者LinearLayoutManager.HORIZONTAL
根据您的方向RecyclerView
。这个对我有用。