An animation library written in Kotlin called "Before After animation" is available in "Before After animation library write in Kotlin in Android Example 365. -after-animation-library-write-in-kotlin /) "was published, so I tried using it.
Move the slide from left to right to gradually switch images.
--Before moving
--After moving
Please prepare the following in advance.
-Android Studio with Kotlin plugin installed
Add the following to the build.gradle of the project.
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' } //Postscript
}
Add the following to the module build.gradle.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// Before After animation library //Postscript
implementation 'com.github.fevziomurtekin:BeforeAfterView:1.0.0' //Postscript
}
Describe the MainActivity.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
Describe the following in res / layout / activitymain.xml.
<com.fevziomurtekin.beforeafterview.BeforeAfterView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:bgColor="@android:color/black"
app:sliderTintColor="@android:color/white"
app:sliderIconTint="@android:color/white"
app:afterSrc="@drawable/after"
app:beforeSrc="@drawable/before"
app:imageHeightPercent="0.5"
app:sliderWidthPercent="0.75"
/>
You can edit the attributes as follows:
ATTRIBUTE | DESCRIPTION |
---|---|
bgColor | The color in int of the background color (by default @android:color/black) |
sliderTintColor | The color int of the slider tint color (by default @android:color/white) |
sliderIconTint | The size in int of the slider icon color (by default @android:color/white) |
afterSrc | The resource in int of the imageview src |
beforeSrc | The resource in int of the imageview src |
imageHeightPercent | The height percent of the imageView (by default 0.55f) |
sliderWidthPercent | The width percent of the sliderView (by default 0.65f) |
Under res / drawable, after.jpg and before.jpg of the image source specified in the layout are stored. Please have an image ready. However, if the image file is large, an error will occur when reading it.
The source is published on Github.
fevziomurtekin/BeforeAfterView
The Apache License 2.0 license.
Now you can easily create an image animation. Why don't you try it by incorporating it into your project or customizing the animation?
Kotlin --Introduction to Kotlin -Chapter 1 First Kotlin Application -Chapter 2 Kotlin Grammar
Android
Java
IDE
Recommended Posts