问题描述
- android sliding中的viewpage切换变白
-
写在最前:
如果有朋友可以帮忙解决这个问题,请在底下留言,或者私信我,或者联系我qq:1065885952,谢谢了哈!!~功能描述:
用sliding实现侧滑。首页是viewpage,包含三个fragment选项卡,可滑动切换。左侧是listview菜单,点击对应的item,首页的fragment会切换。
问题再现:
1. 首次加载进来,首页viewpage显示正常。
2. 切换到左侧菜单,选择第二项。第二项显示正常。
3. 切换到左侧菜单,选择首页(带有viewpage)的fragment,viewpage变白。sliding初始化代码如下:
private void initSliding(Bundle savedInstanceState) { getSlidingMenu().setMode(SlidingMenu.LEFT); getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); getSlidingMenu().setShadowWidthRes(R.dimen.shadow_width); getSlidingMenu().setShadowDrawable(R.drawable.shadow); getSlidingMenu().setBehindOffsetRes(R.dimen.slidingmenu_offset); getSlidingMenu().setFadeDegree(0.35f); if (savedInstanceState != null) { mContent = getSupportFragmentManager().getFragment( savedInstanceState, "mContent"); } if (mContent == null) { mContent = Fragment_Choose.newInstance(); } // 设置主界面的视图 setContentView(R.layout.frame_main_content); getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, mContent).commit(); // 设置左边菜单打开后的视图界面 setBehindContentView(R.layout.frame_left_content); getSupportFragmentManager().beginTransaction().replace(R.id.left_content_id, Fragment_LeftMenu.newInstance()).commit(); }
viewpage初始化代码如下:
public class BtmNaviSwitchAdapter extends FragmentPagerAdapter { private ArrayList<Fragment> mFragments; public BtmNaviSwitchAdapter(FragmentManager fm) { super(fm); mFragments = new ArrayList<Fragment>(); mFragments.add(Fragment_Test.newInstance()); mFragments.add(Fragment_Test.newInstance()); mFragments.add(Fragment_Test.newInstance()); } public BtmNaviSwitchAdapter(FragmentManager fm, ArrayList<Fragment> fragments) { super(fm); } @Override public int getCount() { return mFragments.size(); } @Override public Fragment getItem(int position) { return mFragments.get(position); } }
左侧菜单点击切换首页fragment代码如下:
mLeftListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { String key = ""; switch (position) { case 0: key = "home"; break; case 1: key = "emergencies"; break; default: break; } Activity_Home ma = (Activity_Home) getActivity(); ma.switchContent(key); } }); public void switchContent(String key) { if (mContent.equals(mFragmentList.get(key))) { showMainContent(); return; } mContent = mFragmentList.get(key); getSupportFragmentManager().beginTransaction() .replace(R.id.content_frame, mFragmentList.get(key)).commit(); getSlidingMenu().showContent(); }
时间: 2024-11-03 17:57:59