我正在尝试为我的一个java类设置视图。我在SetLayoutManager和Linear LayoutManager上收到错误。我是初学者,所以任何帮助都会非常感激。
package com.bignerdranch.android.criminalintent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class CrimeListFragment extends Fragment {
private RecyclerView mCrimeRecyclerView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_crime_list, container, false);
mCrimeRecyclerView = (RecyclerView) view.findViewById(R.id.crime_recycler_view);
mCrimeRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
return view;
}
}
答案 0 :(得分:0)
这样做:
...
mCrimeRecyclerView = (RecyclerView) view.findViewById(R.id.crime_recycler_view);
mCrimeRecyclerView.setHasFixedSize(true);
LinearLayoutManager mL = new LinearLayoutManager(view.getContext());
mCrimeRecyclerView.setLayoutManager(mL);