Android实现当ImageView在屏幕中滚动时体现视差效果

时间:2017-02-22 08:40 来源:互联网 作者:源码搜藏收藏

  • 源码类别:图片ImageView
  • 源码大小:未知
  • 编码格式:gbk,utf8,不限
  • 运行环境:Android studio
  • 广告推荐

ScrollParallaxImageView

ScrollParallaxImageView扩展ImageView,并提供视差效果,当它在屏幕上滚动。它可以在任何视图,可以滚动其内容,如ListView,RecyclerView,ScrollView等。

屏幕截图

包括ScrollParallaxImageView到您的项目

用gradle:


	
dependencies {
   compile 'com.gjiazhe:scrollparallaximageview:1.0'
}

使用ScrollParallaxImageView在布局文件就像ImageView


	
<com.gjiazhe.scrollparallaximageview.ScrollParallaxImageView
    android:id="@+id/img"
    android:layout_width="match_parent"
    android:layout_height="180dp"
    android:src="@drawable/pic1"
    android:scaleType="centerCrop" />

在Java代码中设置视差样式


	
ScrollParallaxImageView iv = (ScrollParallaxImageView) findViewById(R.id.img);
iv.setParallaxStyles(new VerticalMovingStyle()); // or other parallax styles

在库中有几个视差样式,但你也可以自定义。只需创建一个类实现接口ScrollParallaxImageView.ParallaxStyle


	
public class MyParallaxStyle implements ScrollParallaxImageView.ParallaxStyle {
  @Override
    public void transform(ScrollParallaxImageView view, Canvas canvas, int x, int y) {
        // Transform the view here, x and y stands for the coordinate of
        // ScrollParallaxImageView's top-left corner.
    }

    @Override
    public void onAttachedToImageView(ScrollParallaxImageView view) {
        // Do something when the style is set to a ScrollParallaxImageView.
    }

    @Override
    public void onDetachedFromImageView(ScrollParallaxImageView view) {
        // Do something when the style is remove from a ScrollParallaxImageView.
    }
}

本站资源仅限于学习研究,严禁从事商业或者非法活动! 源码搜藏网所有源码来自互联网转载与用户上传分享,如果侵犯了您的权益请与我们联系,我们将在24小时内删除!谢谢!

图片ImageView下载排行

最新文章