コード例 #1
0
  public void initContentView() {
    // 底部
    footer = (CustomRadioGroup) findViewById(R.id.main_footer);
    footer.setBackgroundColor(Color.parseColor("#94d8b6"));
    for (int i = 0; i < menu.subMenus.size(); i++) {
      footer.addItem(
          menu.subMenus.get(i).iconNormal,
          menu.subMenus.get(i).iconPressed,
          menu.subMenus.get(i).name);
    }
    // 主体
    body = (ViewPager) findViewById(R.id.main_body);

    final MainBodyPageChangeListener bodyChangeListener = new MainBodyPageChangeListener(footer);
    body.setOnPageChangeListener(bodyChangeListener);

    initFragments();
    body.setOffscreenPageLimit(4);
    MainPagerAdapter mAdapetr = new MainPagerAdapter(getChildFragmentManager(), fragments);
    body.setAdapter(mAdapetr);
    body.setCurrentItem(0);

    footer.setCheckedIndex(body.getCurrentItem());
    footer.setOnItemChangedListener(
        new CustomRadioGroup.OnItemChangedListener() {
          public void onItemChanged() {
            body.setCurrentItem(footer.getCheckedIndex(), false);
          }
        });

    // footer.setItemNewsCount(1, 10);// 设置消息数量

  }
コード例 #2
0
 public void onPageScrolled(int arg0, float arg1, int arg2) {
   if (arg1 != 0.0f) {
     int right, left;
     if (arg0 == customRadioGroup.getCheckedIndex()) {
       // 方向向右
       left = customRadioGroup.getCheckedIndex();
       right = customRadioGroup.getCheckedIndex() + 1;
     } else {
       // 方向向左
       left = customRadioGroup.getCheckedIndex() - 1;
       right = customRadioGroup.getCheckedIndex();
     }
     customRadioGroup.itemChangeChecked(left, right, arg1);
   } else {
     customRadioGroup.setCheckedIndex(arg0);
   }
 }