zoukankan      html  css  js  c++  java
  • 属性动画入门学习

    package com.loaderman.customviewdemo;
    
    import android.animation.ValueAnimator;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
        private TextView tv;
        private Button btn;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            tv = (TextView) findViewById(R.id.tv);
    
            btn = (Button) findViewById(R.id.btn);
            btn.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    doAnimation();
                }
            });
    
            tv.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Toast.makeText(MainActivity.this, "clicked me", Toast.LENGTH_SHORT).show();
                }
            });
        }
        private void doAnimation(){
            ValueAnimator animator = ValueAnimator.ofInt(0,400);//从屏幕的左上角(0,0)到屏幕(400,400)
            animator.setDuration(1000);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                public void onAnimationUpdate(ValueAnimator animation) {
                    int curValue = (Integer)animation.getAnimatedValue();
                    tv.layout(curValue,curValue,curValue+tv.getWidth(),curValue+tv.getHeight());
                }
            });
            animator.start();
        }
    
    
    }
    <?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="com.loaderman.customviewdemo.MainActivity">
    
        <Button
            android:id="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="start anim"
            />
        <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:background="#ffff00"
            android:text="Hello"/>
    
    
    </LinearLayout>
  • 相关阅读:
    CRM安装过程问题总结
    SQL Server Active Directory Helper 无法启动
    CRM导出Excel记录的最大数量
    CRM名词解释
    CRM根据不同的角色过滤视图
    asp.net C# webservice安全性方案
    利用MSCRM4.0 Trace功能跟踪详细错误信息
    事件1058处理过程,处理组策略失败.
    在 Windows Server 2003 中配置网络负载平衡
    对比SQL中简单嵌套查询与非嵌套查询的异同
  • 原文地址:https://www.cnblogs.com/loaderman/p/10195429.html
Copyright © 2011-2022 走看看