ParallaxView Kotlin视差滚动视图

Kotlin 写的 Android 视差滚动,灵活、好用、容易上手,是你搞炫酷 UI 效果的好帮手。自定义 View 做得挺扎实的,滑动过程顺滑,动画也平滑得自然。整个项目结构清晰,配合 Gradle 配置好后,跑起来几乎不用动脑子。

视差滚动的精髓就在“前慢后快”那种层次感,ParallaxView就是这么搞的。背景图随着你滑动轻微位移,看起来就像有点 3D 效果一样。常见场景像是头部 Banner、详情页背景图,放上去立马高级不少。

自定义 View是关键点,继承了ViewViewGroup后,重写onDrawonScrollChanged之类的方法,把位移、透明度这些加进去。动画用的是ObjectAnimator或者ValueAnimator,写起来不麻烦,效果还挺稳。

Kotlin 的简洁在这儿就能体现出来,语法轻便、空安全也管用。再加上 AndroidX 支持,老系统新系统都能跑得溜。如果你熟一点 Kotlin 和自定义 View,那改起来真是得心应手。

布局这块就看你怎么摆前景和背景了,ConstraintLayout用起来还挺舒服。资源方面,动画 XML、样式、颜色什么的都按模块拆好了,改样式也方便。

想加点交互?onTouchEvent()直接拦截用户手势,响应也快,视差跟着动,看起来挺顺眼。生命周期的也不含糊,onResume()onPause()里该停的停,该启的启,避免性能抖动。

如果你想在 App 里加点动感,不妨撸一遍这个源码。ParallaxView 还挺适合做 Demo 或者作为模块集成,顺便还能练练 Kotlin 和自定义 View 的功底。

zip
ParallaxView.zip 预估大小:73个文件
folder
ParallaxView-master 文件夹
file
scroll1.gif 12.49MB
file
.gitignore 118B
folder
app 文件夹
file
.gitignore 7B
file
build.gradle 1KB
folder
src 文件夹
folder
androidTest 文件夹
folder
java 文件夹
folder
net 文件夹
folder
vrgsoft 文件夹
folder
parallaxview 文件夹
file
ExampleInstrumentedTest.kt 650B
folder
main 文件夹
file
AndroidManifest.xml 718B
folder
res 文件夹
folder
mipmap-xhdpi 文件夹
file
ic_launcher_round.png 7KB
file
ic_launcher.png 4KB
folder
mipmap-mdpi 文件夹
file
ic_launcher_round.png 3KB
file
ic_launcher.png 2KB
folder
layout 文件夹
file
item.xml 2KB
file
activity_main.xml 862B
file
fragment_scroll.xml 6KB
folder
mipmap-xxhdpi 文件夹
file
ic_launcher_round.png 10KB
file
ic_launcher.png 6KB
folder
menu 文件夹
file
menu.xml 316B
folder
drawable 文件夹
file
ic_navigate_next.xml 337B
file
ic_launcher_background.xml 5KB
folder
mipmap-anydpi-v26 文件夹
file
ic_launcher_round.xml 272B
file
ic_launcher.xml 272B
folder
drawable-xxxhdpi 文件夹
file
jupiter.png 524KB
file
uranus.png 149KB
file
game_of_thrones_back.png 173KB
file
earth.png 453KB
file
neptune.png 498KB
file
star_wars_front.png 836KB
file
mult_front.png 732KB
file
mult_back.png 70KB
file
star_wars_back.png 1.74MB
file
mars.png 30KB
file
space.jpg 145KB
file
saturn.png 10KB
file
fast_furious_front.png 294KB
file
venus.png 469KB
file
sherlok_front.png 913KB
file
fast_furious_back.png 410KB
file
mercury.png 177KB
file
game_of_thrones_front.png 733KB
file
sherlok_back.png 1.74MB
folder
drawable-v24 文件夹
file
ic_launcher_foreground.xml 2KB
folder
mipmap-hdpi 文件夹
file
ic_launcher_round.png 5KB
file
ic_launcher.png 3KB
folder
mipmap-xxxhdpi 文件夹
file
ic_launcher_round.png 15KB
file
ic_launcher.png 9KB
folder
values 文件夹
file
strings.xml 75B
file
colors.xml 208B
file
styles.xml 383B
folder
java 文件夹
folder
net 文件夹
folder
vrgsoft 文件夹
folder
parallaxview 文件夹
file
TestAdapter.kt 1005B
file
MainActivity.kt 2KB
folder
test 文件夹
folder
java 文件夹
folder
net 文件夹
folder
vrgsoft 文件夹
folder
parallaxview 文件夹
file
ExampleUnitTest.kt 349B
file
proguard-rules.pro 751B
file
settings.gradle 28B
file
build.gradle 678B
file
gradlew 5KB
file
README.md 3KB
file
gradlew.bat 2KB
file
gradle.properties 730B
folder
.idea 文件夹
file
misc.xml 2KB
file
gradle.xml 680B
file
runConfigurations.xml 564B
file
modules.xml 712B
file
scroll2.gif 21.05MB
folder
gradle 文件夹
folder
wrapper 文件夹
file
gradle-wrapper.properties 231B
file
gradle-wrapper.jar 52KB
folder
parallax 文件夹
file
.gitignore 7B
file
build.gradle 943B
folder
src 文件夹
folder
androidTest 文件夹
folder
java 文件夹
folder
net 文件夹
folder
vrgsoft 文件夹
folder
parallaxview 文件夹
file
ExampleInstrumentedTest.java 754B
folder
main 文件夹
file
AndroidManifest.xml 111B
folder
res 文件夹
folder
values 文件夹
file
strings.xml 75B
file
attrs.xml 561B
folder
java 文件夹
folder
net 文件夹
folder
vrgsoft 文件夹
folder
parallaxview 文件夹
file
ParallaxView.kt 5KB
folder
test 文件夹
folder
java 文件夹
folder
net 文件夹
folder
vrgsoft 文件夹
folder
parallaxview 文件夹
file
ExampleUnitTest.java 402B
file
proguard-rules.pro 751B
...
zip 文件大小:42.32MB