android studio开发<二> 动态按钮动画效果

原创


按钮动态效果:


1.在res--drawable--新建一个XML文件。 这里就举例按钮和默认效果,还有其他效果就不写了。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- 按下图片-->
    <item          android:drawable="@drawable/button2"    android:state_pressed="true" />
    <!-- 默认图片-->
    <item          android:drawable="@drawable/button1" />

</selector>

2.在activity_main.xml里设置该按钮的属性,如果不是英文单词会提示文字有误,不用管

android:background="@drawable/happy"
还有一种在代码里直接修改图片的:
myButton.setImageDrawable(getResources().getDrawable(R.drawable.button1));
动画效果:
import android.view.animation.Animation;       --动画包
import android.view.animation.AlphaAnimation;  --透明动画包
import android.view.animation.ScaleAnimation;  --大小动画包
                Animation animation=new AlphaAnimation(1.0f,0.0f);
                animation.setDuration(3000);
                myButton.startAnimation(animation);

                Animation animation3 =new ScaleAnimation(0.8f,0.8f,0.8f,0.8f);
                animation3.setDuration(100);
                myButton.startAnimation(animation3);
</pre><pre code_snippet_id="1869097" snippet_file_name="blog_20160906_3_6083167" name="code" class="java"><pre name="code" class="java">        animation01.setRepeatCount(Animation.INFINITE);  //重复次数
        animation01.setDuration(1200);                   //持续时间
        animation01.setStartOffset(3600);                //多久后开始
        animation01.setRepeatMode(Animation.REVERSE);    //重复模式
<pre style="font-family: 宋体; font-size: 12pt; background-color: rgb(255, 255, 255);">animation.setFillAfter(<span style="color:#000080;"><strong>true</strong></span>); //动画结束保持状态
        //动画事件
        animation01.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                jiantou01.setAlpha(0f);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                jiantou01.setAlpha(1f);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });



 
 
 
 
 
 

 
题外话:U3D显示帧率和内存消耗  fps.ToString("f0")  Profiler.GetTotalAllocatedMemory() / 1024 / 1024计算出来是MB


  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是重阳

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值