ViewPager

  • 1.简介
    • 1)

ViewFlow: gethub上的一个开源项目 废弃掉,有更好的,ViewFlow 相当于 Android UI 部件提供水平滚动的 ViewGroup,动态添加View的功能,也就是说如果你的View数目是不固定的,那么你就应该使用ViewFlow;

ViewPager:不能动态添加View,实现屏幕间的切换。 手势滑动,PagerAdapter接口生成页面视图;

ViewFlipper:继承至FrameLayout,所以它是一个Layout里面可以放置多个View;,系统自带控件之一,主要为在同一个屏幕间的切换及设置动画效果,且可以自动播放

2)ViewFlipper属性:
PageControlView:指示器

android:autoStart="true" <<==>> mViewFlipper.startFlipping();  //自动播放
android:flipInterval="2000" <<==>>mViewFlipper.setFilpInterval(2000);  //设置View之间切换的时间间隔


3)ViewPager

  • 2.深入探索Using ViewPager for Screen Slides 实现屏幕滑动
    • 1)Screen slides are transitions between one entire screen to another and are common with UIs like setup wizards or slideshows. 像幻灯片一样,实现整个屏幕的滑动效果
    • 2)Create the Views:Create a layout file that you’ll later use for the content of a fragment 为屏幕创建一个布局文件
    • 3)Create the Fragment:Create a Fragment class that returns the layout that you just created in the onCreateView() 加载布局、
    • 4)Add a ViewPager: swipe gestures to transition through pages, and they display screen slide animations by default, 默认滑动效果, use PagerAdapters as a supply for new pages to display, 使用页面适配器来提供展示页面
    • 5)Create an activity
      5.1. Sets the content view to be the layout with the ViewPager.
      5.2.创建类继承FragmentStatePagerAdapter,and implements the getItem() method to supply instances of ScreenSlidePageFragment as new pages. 再骑getItem方法中获取新页面的实例
      5.3. implement the getCount() method, which returns the amount of pages the adapter will create 实现getCount方法,这样适配器就好确定需创建的页面数量
      5.4. Hooks up the PagerAdapter to the ViewPager. 对接适配器和适配器视图
      5.5. Handles the device’s back button by moving backwards in the virtual stack of fragments. If the user is already on the first page, go back on the activity back stack.处理返回键,这个也是得分情况考虑,如果是首页,则按照系统默认的activity回退栈方式处理,否则记录下虚拟的fragment队列栈,使用既有的API来处理,不用自己再写实现逻辑。
import android.support.v4.app.Fragment;
...
public class ScreenSlidePageFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        ViewGroup rootView = (ViewGroup) inflater.inflate(
                R.layout.fragment_screen_slide_page, container, false);

        return rootView;
    }
}
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
...
public class ScreenSlidePagerActivity extends FragmentActivity {
    /**
     * The number of pages (wizard steps) to show in this demo.
     */
    private static final int NUM_PAGES = 5;

    /**
     * The pager widget, which handles animation and allows swiping horizontally to access previous
     * and next wizard steps.
     */
    private ViewPager mPager;

    /**
     * The pager adapter, which provides the pages to the view pager widget.
     */
    private PagerAdapter mPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screen_slide);

        // Instantiate a ViewPager and a PagerAdapter.
        mPager = (ViewPager) findViewById(R.id.pager);
        mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
        mPager.setAdapter(mPagerAdapter);
    }
   @Override
    public void onBackPressed() {
        if (mPager.getCurrentItem() == 0) {
            // If the user is currently looking at the first step, allow the system to handle the
            // Back button. This calls finish() on this activity and pops the back stack.
            super.onBackPressed();
        } else {
            // Otherwise, select the previous step.
            mPager.setCurrentItem(mPager.getCurrentItem() - 1);
        }
    }

    /**
     * A simple pager adapter that represents 5 ScreenSlidePageFragment objects, in
     * sequence.
     */
    private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
        public ScreenSlidePagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return new ScreenSlidePageFragment();
        }

        @Override
        public int getCount() {
            return NUM_PAGES;
        }
    }
}
  • 3.个性化定制页面切换效果:Customize the Animation with PageTransformer

    • 1)To display a different animation from the default screen slide animation, implement the ViewPager.PageTransformer interface and supply it to the view pager. 要改变默认的滑动效果,向ViewPager提供一个效果切换器的接口。
    • 2)The interface exposes a single method, transformPage(). 接口暴露一个切换屏幕效果的方法,相邻的页面和当前的页面
    • 3) you can then create custom slide animations by determining which pages need to be transformed based on the position of the page on the screen, which is obtained from the position parameter of the transformPage() method. 所有需要一个位置position参数Based on the position of the pages on the screen, you can create custom slide animations by setting page properties with methods such as setAlpha(), setTranslationX(), or setScaleY(). 设置页面属性
    • 4) call setPageTransformer() with your implementation to apply your custom animations. For example, if you have a PageTransformer named ZoomOutPageTransformer, you can set your custom animations like this: 客户端调用 set方法来获取想要的动漫效果
    • 5)The position parameter indicates where a given page is located relative to the center of the screen. It is a dynamic property that changes as the user scrolls through the pages. When a page fills the screen, its position value is 0. When a page is drawn just off the right side of the screen, its position value is 1. If the user scrolls halfway between pages one and two, page one has a position of -0.5 and page two has a position of 0.5 position的逻辑
    ViewPager mPager = (ViewPager) findViewById(R.id.pager);
    ...
    mPager.setPageTransformer(true, new ZoomOutPageTransformer());

    http://developer.android.com/training/animation/screen-slide.html#pagetransformer
    http://developer.android.com/reference/android/support/v4/view/ViewPager.html
    官方文档提供了两种效果:
    一种是ZoomOutPageTransformer 缩放 这个效果最好
    一种是DepthPageTransformer 深度平滑
    Backgroundtoforegroundtransformer
    默认效果

  • 4.一般的步骤:
    1)两个数据源:分别是图片和点点,图片资源ID
    private ImageView[] mImageViews/dots;
    int[] imgIdArray
    2)分别载入图片资源ID 和点点

  • 5.ConvenientBanner 作为服务器端,提供了一些接口方法

左右滑动效果ViewPager、ViewFlipper、ViewFlow)
http://blog.csdn.net/zhouyuanjing/article/details/8290454

Android ViewPager
:http://blog.csdn.net/wangjinyu501/article/details/8169924

View间渐变
http://hukai.me/android-training-course-in-chinese/animations/screen-slide.html

ViewFlipper:
http://www.cnblogs.com/hanyonglu/archive/2012/02/13/2349827.html
http://blog.sina.com.cn/s/blog_75992b660101lnnw.html

Android使用ViewFlipper实现左右滑动效果面
http://blog.csdn.net/zhy_cheng/article/details/8256507

Android 利用ViewPager实现底部圆点导航左右滑动效果以及Fragment页面切换:
http://blog.csdn.net/a123demi/article/details/39483793

Android ViewPager和Fragment实现顶部导航界面滑动效果
http://blog.csdn.net/a123demi/article/details/39480385

Android 使用ViewPager实现左右循环滑动图片
http://blog.csdn.net/xiaanming/article/details/8966621
http://jameszhao84.iteye.com/blog/1344584

ViewPager and HorizontalScrollVIew冲突问题:
http://stackoverflow.com/questions/6920137/android-viewpager-and-horizontalscrollview

FragmentPagerAdapter及FragmentStatePagerAdapter
http://blog.csdn.net/clx44551/article/details/51249021

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值