我有一个活动,启动一个包含4个标签的片段,每个标签显示一个列表视图,每当我定向到横向时,标签和列表视图都会正确显示但是当我回到垂直,列表视图或我放入的任何内容时标签从中途开始......其余部分是空白的。确切的位置在哪里 我相信这个问题必须与我的android有关:configChanges =“orientation | screenSize”
入职前 http://i1366.photobucket.com/albums/r761/Aeonia92/Screenshot_2015-09-04-10-54-05_zpshdo11fx0.jpeg
迎新之后 http://i1366.photobucket.com/albums/r761/Aeonia92/Screenshot_2015-09-04-11-01-26_zpsptfuvzwj.jpeg
如果我在底层活动的清单中移除此行,那么应用程序一旦转到横向,就会丢失所有内容,包括片段选项卡,以显示空页。
有没有以编程方式执行此操作?
public class ViewPagerFragment extends Fragment {
public List<TabPagerItem> mTabs = new ArrayList<>();
private Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getActivity();
createTabPagerItem();
}
private void createTabPagerItem() {
mTabs.add(new TabPagerItem(getText(R.string.all), HomeFragment.newInstance(getString(R.string.all))));
mTabs.add(new TabPagerItem(getText(R.string.print), PrintFragment.newInstance(getString(R.string.print))));
mTabs.add(new TabPagerItem(getText(R.string.radio), RadioFragment.newInstance(getString(R.string.radio))));
mTabs.add(new TabPagerItem(getText(R.string.tv), TVFragment.newInstance(getString(R.string.tv))));
//mTabs.add(new TabPagerItem(getText(R.string.tv), MainFragment.newInstance(getString(R.string.tv))));
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_viewpager, container, false);
rootView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return rootView;
}
@Override
public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
final ViewPager mViewPager = (ViewPager) view.findViewById(R.id.viewPager);
//pages to store in memory
mViewPager.setOffscreenPageLimit(mTabs.size());
mViewPager.setAdapter(new ViewPagerAdapter(getChildFragmentManager(), mTabs));
getActivity().runOnUiThread(new Runnable() {
public void run() {
(new ViewPagerAdapter(getChildFragmentManager(), mTabs)).notifyDataSetChanged();
}
});
TabLayout mSlidingTabLayout = (TabLayout) view.findViewById(R.id.tabLayout);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mSlidingTabLayout.setElevation(15);
}
mSlidingTabLayout.setupWithViewPager(mViewPager);
}
示例片段
public static HomeFragment newInstance(String text) {
HomeFragment mFragment = new HomeFragment();
Bundle mBundle = new Bundle();
mBundle.putString("f", text);
mFragment.setArguments(mBundle);
return mFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.homelist, container, false);
setHasOptionsMenu(true);
((MainActivity) getActivity())
.setActionBarTitle("Latest Mentions");
context = getActivity();
info = new Db(context);
anime = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_up);
New();
rootView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return rootView;
}