您的位置:首页 > 移动开发

Spark - 创建类似于 Instagram&Spotify App 的登录界面的动态渐变背景

2018-04-10 10:51 696 查看
https://github.com/TonnyL/Spark

截图



用法

private lateinit var mSpark: Spark

override fun onCreate(savedInstanceState: Bundle?) {
// ...

mSpark = Spark.Builder()
.setView(frameLayout) // View or view group
.setDuration(4000)
.setAnimList(Spark.ANIM_GREEN_PURPLE)
.build()

}

override fun onResume() {
// ...
mSpark.startAnimation()
}

override fun onPause() {
// ...
mSpark.stopAnimation()
}

安装

Gradle

将下面的代码添加到根 build.gradle 文件中:

repositories {
maven { url "https://jitpack.io" }
}


将下面的代码添加到 module 的 build.gradle 文件中:

dependencies {
implementation 'io.github.tonnyl:spark:x.y.z'
}

Maven

<dependency>
<groupId>io.github.tonnyl</groupId>
<artifactId>spark</artifactId>
<version>x.y.z</version>
<type>pom</type>
</dependency>

自定义渐变色列表

创建渐变 drawable

purple_drawable.xml


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<gradient
android:centerColor="#e459aa"
android:endColor="#cd7be6"
android:startColor="#f14589"
android:type="linear" />

<corners android:radius="0dp" />

</shape>

yellow_drawable.xml


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<gradient
android:centerColor="#F4A37B"
android:endColor="#F08875"
android:startColor="#F9CB87"
android:type="linear"/>

<corners android:radius="0dp" />

</shape>

创建动画列表

custom_anim_list.xml


<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">

<item
android:drawable="@drawable/yellow_drawable"
android:duration="4500" />

<item
android:drawable="@drawable/purple_drawable"
android:duration="4500" />

</animation-list>

应用动画列表

mSpark = Spark.Builder()
// ...
.setAnimList(R.drawable.custom_anim_list) // Your custom animation
// ...

致谢

Designed by Alexander Zaytsev.



许可证

MIT
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息