关于一些动画和特效的收集,碰到了就收集

一 类似全民飞机大战那种按钮点击之后缩小一点马上回复的效果。

另外长按缩的更小。

用scaleanimation来实现

类似这样

/*
  * animate scale
  */
 final ScaleAnimation animation =new ScaleAnimation(1.0f,0.8f, 1.0f, 0.8f,
   Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

left_lin=(LinearLayout)findViewById(R.id.left_lin);
  left_lin.setOnClickListener(new View.OnClickListener() {   
   @Override
   public void onClick(View v) {
    /*
     * animate scale
     */
    animation.setDuration(500);   
    left_lin.startAnimation(animation);
   }
  });

效果蛮不错的,1.0代表原始大小,0.8是缩放后的大小,Animation.RELATIVE_TO_SELF是指相对自己来说,0.5f是x轴或者Y轴缩放中心点坐标。

2.浮层按钮效果 很多app现在为了突出某个功能,会有一个浮在界面内容上面的类似蓝色图标的按钮。

http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/1028/1857.html 记录了这个实现方法

还有一个大神搜集了一个网站,总结了一些开源的免费的特效

http://www.open-open.com/lib/view/open1411443332703.html

收集android上开源的酷炫的交互动画和视觉效果:Interactive-animation

以下摘抄

要实现float action button可以有多种方法,一种只适合android L,另外一种适合任意版本。

用ImageButton实现

这种方式其实是在ImageButton的属性中使用了android L才有的一些特性:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

<ImageButton

android:layout_width="56dp"

android:layout_height="56dp"

android:src="@drawable/plus"

android:layout_alignParentBottom="true"

android:layout_alignParentRight="true"

android:layout_marginRight="16dp"

android:layout_marginBottom="16dp"

android:tint="@android:color/white"

android:id="@+id/fab"

android:elevation="1dp"

android:background="@drawable/ripple"

android:stateListAnimator="@anim/fab_anim"

/>

仔细一点,你会发现我们将这个ImageButton放到了布局的右下角,为了实现float action button应该具备的效果,需要考虑以下几个方面:

·Background

·Shadow

·Animation

背景上我们使用ripple drawable来增强吸引力。注意上面的xml代码中我们将background设置成了@drawable/ripple ,ripple drawable的定义如下:


1

2

3

4

5

6

7

<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:colorControlHighlight">

    <item>

        <shape android:shape="oval">

            <solid android:color="?android:colorAccent" />

        </shape>

    </item>

</ripple>

既然是悬浮按钮,那就需要强调维度上面的感觉,当按钮被按下的时候,按钮的阴影需要扩大,并且这个过程是渐变的,我们使用属性动画去改变translatioz。


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item

        android:state_enabled="true"

        android:state_pressed="true">

        <objectAnimator

            android:duration="@android:integer/config_shortAnimTime"

            android:propertyName="translationZ"

            android:valueFrom="@dimen/start_z"

            android:valueTo="@dimen/end_z"

            android:valueType="floatType" />

    </item>

    <item>

        <objectAnimator

            android:duration="@android:integer/config_shortAnimTime"

            android:propertyName="translationZ"

            android:valueFrom="@dimen/end_z"

            android:valueTo="@dimen/start_z"

            android:valueType="floatType" />

    </item>

</selector>

使用自定义控件的方式实现悬浮按钮

这种方式不依赖于android L,而是码代码。

首先定义一个这样的类:


1

2

3

public class CustomFAB extends ImageButton {

...

}

然后是读取一些自定义的属性(假设你了解styleable的用法)


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

private void init(AttributeSet attrSet) {

    Resources.Theme theme = ctx.getTheme();

    TypedArray arr = theme.obtainStyledAttributes(attrSet, R.styleable.FAB, 0, 0);

    try {

        setBgColor(arr.getColor(R.styleable.FAB_bg_color, Color.BLUE));

        setBgColorPressed(arr.getColor(R.styleable.FAB_bg_color_pressed, Color.GRAY));

        StateListDrawable sld = new StateListDrawable();

        sld.addState(new int[] {android.R.attr.state_pressed}, createButton(bgColorPressed));

        sld.addState(new int[] {}, createButton(bgColor));

        setBackground(sld);

    }

    catch(Throwable t) {}

    finally {

         arr.recycle();

    }

}

在xml中我们需要加入如下代码,一般是在attr.xml文件中。


1

2

3

4

5

6

7

8

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <declare-styleable name="FAB">

        <!-- Background color -->

        <attr name="bg_color" format="color|reference"/>

        <attr name="bg_color_pressed" format="color|reference"/>

    </declare-styleable>

</resources>

使用StateListDrawable来实现不同状态下的背景


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

private Drawable createButton(int color) {

    OvalShape oShape = new OvalShape();

    ShapeDrawable sd = new ShapeDrawable(oShape);

    setWillNotDraw(false);

    sd.getPaint().setColor(color);

    OvalShape oShape1 = new OvalShape();

    ShapeDrawable sd1 = new ShapeDrawable(oShape);

    sd1.setShaderFactory(new ShapeDrawable.ShaderFactory() {

        @Override

        public Shader resize(int width, int height) {

            LinearGradient lg = new LinearGradient(0,0,0, height,

            new int[] {

                Color.WHITE,

                Color.GRAY,

                Color.DKGRAY,

                Color.BLACK

            }, null, Shader.TileMode.REPEAT);

            return lg;

        }

    });

    LayerDrawable ld = new LayerDrawable(new Drawable[] { sd1, sd });

    ld.setLayerInset(0, 5, 5, 0, 0);

    ld.setLayerInset(1, 0, 0, 5, 5);

    return ld;

}

最后将控件放xml中:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    xmlns:custom="http://schemas.android.com/apk/res/com.survivingwithandroid.fab"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:paddingBottom="@dimen/activity_vertical_margin"

    tools:context=".MyActivity">

...

    <com.survivingwithandroid.fab.CustomFAB

        android:layout_width="56dp"

        android:layout_height="56dp"

        android:src="@android:drawable/ic_input_add"

        android:layout_alignParentBottom="true"

        android:layout_alignParentRight="true"

        android:layout_marginRight="16dp"

        android:layout_marginBottom="16dp"

        custom:bg_color="@color/light_blue"

        android:tint="@android:color/white"

     />

</RelativeLayout>

时间: 2024-08-29 11:53:30

关于一些动画和特效的收集,碰到了就收集的相关文章

JQuery之动画与特效

学编程吧JQuery之动画与特效发布了,欢迎通过xuebiancheng8.com 显示与隐藏 show(spped,[callback])与hide(spped,[callback]) speed可选填slow.normal.fast,对应的速度分别为600ms.400ms.200ms.也可以直接填毫秒数,callback函数为回调函数,动作完成后调用此函数 [javascript] view plaincopyprint? $("img").show(3000,function()

基于animation.css实现动画旋转特效

分享一款基于animation.css实现动画旋转特效.这是一款基于CSS3实现的酷炫的动画旋转特效代码.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class="wrap"> <div class="mod_bg"> <div class="bg1"></div> <div class="bg2"></div> <

jQuery复习—用动画和特效装扮页面(队列未整理)

用动画和特效装扮页面 一.显示和隐藏元素 设置元素的style.display属性(none/block/inline) 1.简单的改变元素显示和隐藏 (1).显示 show() (2).隐藏 hide() (3).切换状态 toggle() 2.渐变的显示和隐藏元素 (1).显示 show(speed,callback) (2).隐藏 hide(speed,callback) (3).切换状态 toggle(speed,callback) 参数说明: speed: 数字或者字符串.可以是若干毫

15款css3鼠标悬停图片动画过渡特效

分享15款css3鼠标悬停图片动画过渡特效.这是一款15款不同效果的css3 hover动画过渡效果代码.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class="htmleaf-container"> <div class="container bs-docs-container"> <div class="row"> <div class="col-md-3

基于jQuery点击加载动画按钮特效

分享一款基于jQuery点击加载动画按钮特效.这是一款基于jQuery+CSS3实现的鼠标点击按钮加载动画特效代码.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class="container"> <div class="row"> <div class="col-md-6 col-md-offset-3 text-center"> <p> <button c

jQuery动画与特效

参考:jQuery权威指南jQuery初步jQuery选择器jQuery操作domjQuery操作dom事件jQuery插件jQuery操作AjaxjQuery动画与特效jQuery实现导航栏jQuery实现点击式选项卡jQuery实现select三级联动 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 4

iOS动画和特效(一)UIView动画和CoreAnimation

一个简单的例子作为iOS动画系类的开始 QuickExampleViewController UIView的方法中有几个易用的静态方法可以做出动画效果,分别是UIView.beginAnimations() -> UIView.commitAnimations() 和UIView.animateWithDuration()方法 我们以一个UIView,每点击一次向右移动100,变色,加速运动这个简单的动效作为例子. 转载请注明出处 使用UIView.beginAnimations() -> U

信息收集之主动信息收集(一)

主动信息收集: 1.主机发现 1.1二层主机发现 1.2三层主机发现 1.3四层主机发现 2.端口扫描 2.1TCP端口扫描 2.2UDP端口扫描 2.3僵尸扫描 3.服务识别 3.1 python socket 3.2 dmitry -pb 3.3 nmap 3.4 amap -B 4.操作系统识别 4.1 nmap 4.2 TTL 主动信息收集 直接与目标系统交互通信 使用受控的第三方电脑进行探测 使用代理或者已经被控制的主机 使用噪声迷惑目标,淹没真实的探测流量  #伪造不同的IP给目标发

信息收集之主动信息收集(二)

1.SNMP扫描 2.SMB扫描 3.SMTP扫描 4.防火墙识别 5.WAF识别 6.负载均衡识别 一.SNMP扫描 SNMP 简单网络管理协议,经常被错误的配置,信息的金矿 SNMP服务是使用明文传输的,即使不能通过community进行查询,也有可能使用抓包嗅探的方法得到SNMP数据包中的数据 SNMP系统的内部信息都是可以通过snmp进行监控的 SNMP服务端UDP 161  客户端 UDP 162 1.onesixtyone实现SNMP扫描 首先在目标机(xp)上安装SNMP协议并启动