/** 初始化水平滚动翻页 */ private void initPageScroll() { fdScrollLayout = (FDScrollLayout) findViewById(R.id.main_scrolllayout); // fdScrollLayout.setIsScroll(false); RadioGroup mainBarLayout = (RadioGroup) findViewById(R.id.fd_main_tabbar); // fdHeadTitles = getResources().getStringArray(R.array.head_titles); fdViewCount = fdScrollLayout.getChildCount(); radioButtons = new RadioButton[fdViewCount]; for (int i = 0; i < fdViewCount; i++) { radioButtons[i] = (RadioButton) mainBarLayout.getChildAt(i); radioButtons[i].setTag(i); radioButtons[i].setChecked(false); radioButtons[i].setOnClickListener( new View.OnClickListener() { public void onClick(View view) { int posistion = (Integer) (view.getTag()); // 点击当前项刷新 if (currentSelect == posistion) { switch (posistion) { case 0: // 首页 break; case 1: // 搜索 initSearchView(); break; case 2: // 优惠 break; case 3: // 个人 break; } } fdScrollLayout.snapToScreen(posistion); } }); } // 设置第一显示屏 currentSelect = 0; radioButtons[currentSelect].setChecked(true); fdScrollLayout.setOnViewChangeListener( new FDScrollLayout.OnViewChangeListener() { public void OnViewChange(int viewIndex) { // 切换列表视图-如果列表数据为空:加载数据 switch (viewIndex) { case 0: // 首页 break; case 1: // 搜索 break; case 2: // 优惠 break; case 3: // 个人 // 判断登录 break; } setCurrentPoint(viewIndex); } }); }
// 切换到.. public void setPageIndex(int index) { if (index < 0 || index > fdViewCount - 1 || currentSelect == index) return; radioButtons[currentSelect].setChecked(false); radioButtons[index].setChecked(true); currentSelect = index; fdScrollLayout.snapToScreen(index); }