鱼C论坛

 找回密码
 立即注册
查看: 3241|回复: 0

[技术交流] kotlin for android动画制作之颜色渐变动画

[复制链接]
发表于 2017-12-5 11:07:38 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
        我们继续使用昨天的项目,修改fragment_blank.xml文件:
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.     android:layout_width="match_parent"
  3.     android:layout_height="match_parent"
  4.     android:orientation="vertical"
  5.     >

  6.     <!-- TODO: Update blank fragment layout -->
  7.     <TextView
  8.         android:id="@+id/idtexta"
  9.         android:layout_width="match_parent"
  10.         android:layout_height="200dp"
  11.         android:background="#ffff00"
  12.         android:text="@string/hello_blank_fragment" />
  13.     <Button
  14.         android:id="@+id/idbuttona"
  15.         android:text="颜色渐变"
  16.         android:layout_width="wrap_content"
  17.         android:layout_height="wrap_content" />

  18. </LinearLayout>
复制代码

        我们只是换了个线性布局,添加了个按钮。然后修改BlankFragment.kt文件:
  1. package com.example.xinwei.fragmentkotlin

  2. import android.app.Fragment
  3. import android.os.Bundle
  4. import android.view.LayoutInflater
  5. import android.view.View
  6. import android.view.ViewGroup
  7. import android.view.animation.AlphaAnimation
  8. import android.view.animation.Animation
  9. import android.widget.Button
  10. import android.widget.TextView
  11. import kotlinx.android.synthetic.main.fragment_blank.*

  12. class BlankFragment : Fragment() {


  13.     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
  14.                               savedInstanceState: Bundle?): View? {
  15.         var view=inflater.inflate(R.layout.fragment_blank, container, false)
  16.         var animation=AlphaAnimation(0.0f,1.0f)
  17.         animation.duration=3000
  18.         animation.repeatMode=Animation.REVERSE
  19.         var button=view.findViewById<Button>(R.id.idbuttona)
  20.         var textView=view.findViewById<TextView>(R.id.idtexta)
  21.         button.setOnClickListener {
  22.             textView.startAnimation(animation)
  23.         }
  24.         return view
  25.     }

  26. }
复制代码

        点击按钮后就会产生颜色渐变的效果,如图:
jdfw.gif

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 03:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表