即使在切换标签后,我也试图让Recyclerview保持填充状态。 我现在已经花了一段时间,尝试了几种方法,但都没有用。
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
initTab
}
private void initTab(){
//tab setup
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(MainActivity.this,getSupportFragmentManager(),android.R.id.tabcontent);
...
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator(createTabView(icon_search, "search")),
searchFragment.class, null);
...more tabs added...
return;
片段
private RecyclerView results;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
final Bundle savedInstanceState){
View v = inflater.inflate(R.layout.tab_search, container, false);
results = (RecyclerView) v.findViewById(R.id.search_results);
results.setHasFixedSize(true);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
results.setLayoutManager(mLayoutManager);
ScrollListener mScrollListener = new ScrollListener(mLayoutManager);
results.setAdapter(searchResultsAdapter);
results.addOnScrollListener(mScrollListener);
return v;
我不能让mLayoutManager成为单身人士,否则我会从recyclerview那里得到错误
“LayoutManager已经附加到RecyclerView”
纵向模式已锁定且MainActivity未切换到其他活动