1 Star 71 Fork 32

John-逍遥 / android_plugin_readme

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README_AccelerateDecelerateInterpolator.md 2.66 KB
一键复制 编辑 原始数据 按行查看 历史
cfwp007 提交于 2020-06-01 15:24 . 完善readme说明

AccelerateDecelerateInterpolator 代码展示

以下只展示关键部分

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".MainActivity">
    
    ...
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/imgBall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:src="@drawable/ic_ball"/>
        
        ...
        <Button
            android:id="@+id/btClick"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#333333"
            android:layout_alignParentEnd="true"
            android:text="开始动画"/>
    </RelativeLayout>
</LinearLayout>
MainActivity.kt
package com.lujianfei.plugin4_1

import android.content.DialogInterface
import android.content.Intent
import android.net.Uri
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import com.lujianfei.module_plugin_base.base.BasePluginActivity
import com.lujianfei.module_plugin_base.beans.PluginActivityBean
import com.lujianfei.module_plugin_base.utils.DensityUtils


class MainActivity : BasePluginActivity() {
    companion object {
        const val TAG = "MainActivity"
        const val DURATION = 2000L
    }

    private var lastDuration = DURATION
    private var imgBall: ImageView? = null
    ...    
    private var btClick: View? = null

    override fun resouceId(): Int = R.layout.activity_main

    override fun initView() {
       ...
        btClick = findViewById(R.id.btClick)
        imgBall = findViewById(R.id.imgBall)
       ...
    }

   ...

    override fun initEvent() {
       ...
        btClick?.setOnClickListener {
            imgBall?.translationY = 0f
            val animate = imgBall?.animate()
            animate?.apply {
                interpolator = AccelerateDecelerateInterpolator()
                duration = lastDuration
                DensityUtils.getScreenHeight()?.toFloat()?.let { ScreenHeight -> translationY(ScreenHeight * 0.7f) }
                start()
            }
        }
       ...
    }

   ...
}
Android
1
https://gitee.com/lujianfei/android_plugin_readme.git
git@gitee.com:lujianfei/android_plugin_readme.git
lujianfei
android_plugin_readme
android_plugin_readme
master

搜索帮助