سلام بر عزیزای دل ، امروز با قسمتی دیگر از آموزش های فوق العاده کدایت خدمت شما عزیزان هستیم . امروز در ادامه مباحث آموزش کاتلین باری دیگری مبحثی از انیمیشن ها و این بار مبحث انیمیشن Yoyo در کاتلین را برای شما عزیزان آموزش میدهیم .
انیمیشن در کاتلین در زیبا سازی اپلیکیشن ما چه تاثیری دارد
همه ی ما ها روزانه با برنامه اندرویدی زیادی سر و کار داریم . و همیشه هم اون برنامه های که زیبای ظاهری دارند . و جلوه انیمیشن خوب و مناسبی در آن ها استفاده شده مورد اقبال ما قرار میگیرد . خیلی ساده بخوام بهتون بگم منظورم اینه که عقل مردم به چششون هست . و بیشتر جذب چیز هایی میشوند که زیبای ظاهری دارند . سعی کنید در برنامه های اندرویدی خودتون از انیمیشن های مناسب استفاده کنید . تا کاربران را به برنامه شما جذب شوند.

انیمیشن در اندروید
Yoyo Animation در برنامه نویسی اندروید به زبان کاتلین
انیمیشن Yoyo در کاتلین یکی از Animation های جذاب و پر کاربرد می باشد . که دارای افکت زیادی برای ویجت های مختلف می باشد و شما با استفاده از انیمیشن yoyo در کاتلین میتوانید افکت مورد نظرتون رو روی هر کدام از آلمان های خودتون در کاتلین پیاده سازی کنید . خب ، بریم سراغ پیاده سازی انیمیشن Yoyo در کاتلین اول از همه ی پروژه ایجاد کنید . و یک اسم دلخواه برای آن قرار دهید . ولی من خودم اسمشو میزارم Yoyo ، حالا باید کتابخانه این انیمیشن در کاتلین را باید اضافه کنیم . مانند قبل وارد مسیر build.gradle (Module:app) بشوید و کتابخانه زیر را در آن قسمت وارد سازید .
implementation 'com.daimajia.androidanimations:library:2.4@aar'
بعد از این کار من در قسمت Xml اکتیویتی خودم یک ImageView درست می کنم تا روی آن افکت انیمیشن Yoyo را اعمال کنم .
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Yoyo"> <ImageView android:id="@+id/imageview" android:layout_width="150sp" android:layout_height="150sp" android:layout_centerHorizontal="true" android:layout_marginTop="100dp" android:adjustViewBounds="true" android:scaleType="centerCrop" android:src="@drawable/baseline_camera_white_24dp" app:tint="#78052C" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="10dp" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/btn1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_weight="1" android:text="Tada" /> <Button android:id="@+id/btn2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_weight="1" android:text="Bounce" /> <Button android:id="@+id/btn3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_weight="1" android:text="RotateIn" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/btn4" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_weight="1" android:text="FadeIn" /> <Button android:id="@+id/btn5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_weight="1" android:text="Flash" /> <Button android:id="@+id/btn6" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_weight="1" android:text="ZoomIn" /> </LinearLayout> </LinearLayout> </RelativeLayout>
و اما کد قسمت اکتیویتی که شامل انیمیشن yoyo میباشد . که بروی imageview ما اعمال میشود . لازم به ذکر است که انیمیشن یو یو افکت زیادی دارد و من فقط تعدادی از آن ها را برای شما بعنوان مثال نمایش میدهم.
package com.example.retrofit import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.Button import android.widget.ImageView import com.daimajia.androidanimations.library.Techniques import com.daimajia.androidanimations.library.YoYo class Yoyo : AppCompatActivity(), View.OnClickListener { lateinit var imageview: ImageView lateinit var btn1: Button lateinit var btn2: Button lateinit var btn3: Button lateinit var btn4: Button lateinit var btn5: Button lateinit var btn6: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_yoyo) imageview = findViewById(R.id.imageview) btn1 = findViewById(R.id.btn1) btn2 = findViewById(R.id.btn2) btn3 = findViewById(R.id.btn3) btn4 = findViewById(R.id.btn4) btn5 = findViewById(R.id.btn5) btn6 = findViewById(R.id.btn6) btn1.setOnClickListener(this) btn2.setOnClickListener(this) btn3.setOnClickListener(this) btn4.setOnClickListener(this) btn5.setOnClickListener(this) btn6.setOnClickListener(this) } override fun onClick(v: View?) { when(val Id=v?.id){ R.id.btn1->{ YoYo.with(Techniques.Tada) .duration(700) .repeat(5) .playOn(findViewById(R.id.imageview)) }R.id.btn2->{ YoYo.with(Techniques.Bounce) .duration(700) .repeat(5) .playOn(findViewById(R.id.imageview)) }R.id.btn3->{ YoYo.with(Techniques.RotateIn) .duration(700) .repeat(5) .playOn(findViewById(R.id.imageview)) }R.id.btn4->{ YoYo.with(Techniques.FadeIn) .duration(700) .repeat(5) .playOn(findViewById(R.id.imageview)) }R.id.btn5->{ YoYo.with(Techniques.Flash) .duration(700) .repeat(5) .playOn(findViewById(R.id.imageview)) }R.id.btn6->{ YoYo.with(Techniques.ZoomIn) .duration(700) .repeat(5) .playOn(findViewById(R.id.imageview)) } } } }
و در پایان خروجی برنامه به شکل زیر می باشد .
کلام آخر
ما در این سری از آموزش های کاتلین مباحث مختلفی از Animation ها در برنامه نویسی زبان Kotlin را برای شما آموزش دادیم . به غیره از پست امروزمون آموزش جامع در مورد انیمیشن ها و همچنین مبحث switch animation در کاتلین را نیز برای شما آموزش دادیم تا مشکل زیادی در مورد انیمیشن ها نداشته باشید و مشکلاتتون در مورد این مبحث یعنی مباحث مربوط به انیمیشن ها برطرف شده باشد .
موفق باشین .
دیدگاهتان را بنویسید