鱼C论坛

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

[技术交流] kotlin for android 之旋转动画

[复制链接]
发表于 2017-12-7 06:03:51 | 显示全部楼层 |阅读模式

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

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

x
        继续昨天的项目,这次我们利用上第二个fragment,修改fragment_blank_fragment2.xml文件:
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.     xmlns:tools="http://schemas.android.com/tools"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:orientation="vertical"
  6.     tools:context="com.example.xinwei.fragmentkotlin.BlankFragment2">

  7.     <TextView
  8.         android:id="@+id/idtextb"
  9.         android:layout_width="300dp"
  10.         android:layout_height="70dp"
  11.         android:background="#ff0000"
  12.         android:layout_marginTop="150dp"
  13.         android:layout_gravity="center_horizontal"
  14.         android:text="@string/hello_blank_fragment" />

  15.     <Button
  16.         android:id="@+id/idbuttonc"
  17.         android:layout_width="wrap_content"
  18.         android:layout_height="wrap_content"
  19.         android:layout_gravity="center_horizontal"
  20.         android:layout_marginTop="150dp"
  21.         android:text="旋转" />

  22. </LinearLayout>
复制代码

        修改BlankFragment2.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.RotateAnimation
  8. import android.widget.Button
  9. import android.widget.TextView

  10. class BlankFragment2 : Fragment() {
  11.     var view1:View?=null
  12.     var button1:Button?=null
  13.     var text:TextView?=null
  14.     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
  15.                               savedInstanceState: Bundle?): View? {
  16.         view1=inflater.inflate(R.layout.fragment_blank_fragment2, container, false)
  17.         button1=view1?.findViewById<Button>(R.id.idbuttonc)
  18.         text=view1?.findViewById<TextView>(R.id.idtextb)
  19.         rotateRect()
  20.         return view1
  21.     }

  22.     private fun rotateRect() {
  23.         var rotate=RotateAnimation(0.0f,360.0f,350.0f,35.0f)
  24.         rotate.duration=3000
  25.         button1?.setOnClickListener {
  26.             text?.startAnimation(rotate)
  27.         }
  28.     }

  29. }
复制代码

        效果图:
jdfw.gif

本帖被以下淘专辑推荐:

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-27 04:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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