当前位置:  开发笔记 > 编程语言 > 正文

LinearLayoutManager无法解析getOrientation()

如何解决《LinearLayoutManager无法解析getOrientation()》经验,为你挑选了2个好方法。

我有一个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。这个对我有用。



1> 小智..:

更改

private RecyclerView.LayoutManager mLayoutManager;

private LinearLayoutManager mLayoutManager;



2> Zin Win Htet..:

创建分隔线时遇到相同的问题。您可以简单地自己输入方向,LinearLayoutManager.VERTICAL或者LinearLayoutManager.HORIZONTAL根据您的方向RecyclerView。这个对我有用。

推荐阅读
放ch养奶牛
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有