LinearLayoutManager 无法解析 getOrientation()
LinearLayoutManager cannot resolve getOrientation()
我在一个片段中实现了 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;
}
我在创建分隔线时遇到了同样的问题。
你可以根据你的 RecyclerView
的方向自己简单地设置方向,LinearLayoutManager.VERTICAL
或 LinearLayoutManager.HORIZONTAL
。它对我有用。
改变
private RecyclerView.LayoutManager mLayoutManager;
至
private LinearLayoutManager mLayoutManager;
您可以在 XML 文件的 CardView 中使用下面的代码
不在 recyclerView。
android:layout_marginTop="8dp
我在一个片段中实现了 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;
}
我在创建分隔线时遇到了同样的问题。
你可以根据你的 RecyclerView
的方向自己简单地设置方向,LinearLayoutManager.VERTICAL
或 LinearLayoutManager.HORIZONTAL
。它对我有用。
改变
private RecyclerView.LayoutManager mLayoutManager;
至
private LinearLayoutManager mLayoutManager;
您可以在 XML 文件的 CardView 中使用下面的代码 不在 recyclerView。
android:layout_marginTop="8dp