鱼C论坛

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

[技术交流] kotlin for android 之缩放大小

[复制链接]
发表于 2017-12-6 08:26:09 | 显示全部楼层 |阅读模式

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

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

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.     <Button
  19.         android:id="@+id/idbuttonb"
  20.         android:text="缩放大小"
  21.         android:layout_width="wrap_content"
  22.         android:layout_height="wrap_content" />

  23. </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.view.animation.ScaleAnimation
  10. import android.widget.Button
  11. import android.widget.TextView
  12. import kotlinx.android.synthetic.main.fragment_blank.*

  13. class BlankFragment : Fragment() {

  14.     var textView:TextView?=null

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

  30.     private fun scaleAnimation() {
  31.         var button2=view1?.findViewById<Button>(R.id.idbuttonb)
  32.         var scale=ScaleAnimation(0.1f,1.0f,0.1f,1.0f,0.5f,0.5f)
  33.         scale.duration=3000
  34.         scale.repeatMode=Animation.REVERSE
  35.         button2?.setOnClickListener {
  36.             textView?.startAnimation(scale)
  37.         }
  38.     }

  39. }
复制代码

        这里面的scaleAnimation()方法就是缩放大小的代码,效果图:
jdfw.gif

本帖被以下淘专辑推荐:

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-29 22:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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