发表于: 2018-10-04 23:21:32

0 674


一、今天完成的事情

      1.使用ViewPager + Fragment实现滑动加点击切换页面的效果

                 

      通过分别设置点击事件监听和滑动事件监听来实现效果

/**
* 设置底栏点击事件监听
*/
public class MyOnClickListener implements View.OnClickListener {

   private int index = 0;

   public MyOnClickListener(int index) {
       this.index = index;
   }

   @Override
   public void onClick(View view) {
       viewPager.setCurrentItem(index);
   }
}

/**
* 设置页面滑动事件监听
*/
public class MyOnPageChangeListener implements ViewPager.OnPageChangeListener {

    @Override
    public void onPageSelected(int position) {
         switch(position) 
            //滑动到页面0(主页home)
            case 0:
               if (currentIndex == 1) { //从页面1到页面0
                    resetBottomTab();
                    setBottomTab(position);
                } else if(currentIndex == 2) {//从页面2到页面0
                    resetBottomTab();
                    setBottomTab(position);
                }
                break;

            //滑动到页面1(浏览页explore)
            case 1:
               if (currentIndex == 0) { //从页面0到页面1
                    resetBottomTab();
                    setBottomTab(position);
                } else if(currentIndex == 2) {//从页面2到页面1
                    resetBottomTab();
                    setBottomTab(position);
                }
                break;
            //滑动到页面2(我的页me)
            case 2:
                if (currentIndex == 0) { //从页面0到页面2
                    resetBottomTab();
                    setBottomTab(position);
                } else if(currentIndex == 1) {//从页面1到页面2
                    resetBottomTab();
                    setBottomTab(position);
                }
                break;
        }
        currentIndex = position;
    }

   @Override
   public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

   }

   @Override
   public void onPageScrollStateChanged(int state) {

   }

}

  

2.使用SwipeRefreshLayout实现下拉刷新效果

       

     使用SwipeRefreshLayout可以实现下拉刷新,前提是布局里需要包裹一个可以滑动的子控件,然后在代码里设置OnRefreshListener设置监听,最后在监听里设置刷新时的数据获取就可以了。


二、明天计划的事情

      1.完善下拉刷新功能

      2.添加上拉加载。


三、遇到的问题

       刚进入应用时,数据确实已经加载到本地,但没有显示在RecyclerView中,向左或向右切换页面后,RecyclerView才显示数据。


四、收获

      学会了ViewPager的更多用法,第一次接触SwipeRefreshLayout,对其有了简单了解



返回列表 返回列表
评论

    分享到