有关Drawable状态的选择,书写规范。以及GridView、ListView几种LayoutAnimation汇总

今天研究ApiDemo时发现谷歌官方selector书写的标准相当规范。现总结如下:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/textfield_default" />
    <item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_disabled" />
    <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_selected" />
    <item android:state_enabled="true" android:drawable="@drawable/textfield_default" />
    <item android:state_focused="true" android:drawable="@drawable/textfield_disabled_selected" />
    <item android:drawable="@drawable/textfield_disabled" />
</selector>


ApiDemo实现的几种LayoutAnimation加载方式:

1、layout_grid_fade  图标渐显式出现

<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:rowDelay="50%"
        android:directionPriority="column"
        android:animation="@anim/fade" />

2、Layout 添加自定义动画出现

      setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, mStrings));

        AnimationSet set = new AnimationSet(true);

        Animation animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(1000);
        set.addAnimation(animation);
        /**
         * TranslateAnimation 表示位移动画。其中几种构造方法如下:
         * TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
         * float fromXDelta:这个参数表示动画开始的点离当前View X坐标上的差值;
         * float toXDelta, 这个参数表示动画结束的点离当前View X坐标上的差值;
         * float fromYDelta, 这个参数表示动画开始的点离当前View Y坐标上的差值;
         * float toYDelta)这个参数表示动画开始的点离当前View Y坐标上的差值;)
         * 如果view在A(x,y)点 那么动画就是从B点(x+fromXDelta, y+fromYDelta)点移动到C 点(x+toXDelta,y+toYDelta)点.
         * 
         * 第二种构造方法如下:
         * TranslateAnimation (int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)
         * fromXType:第一个参数是x轴方向的值的参照(Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF,or Animation.RELATIVE_TO_PARENT);
         * fromXValue:第二个参数是第一个参数类型的起始值;
         * toXType,toXValue:第三个参数与第四个参数是x轴方向的终点参照与对应值;
         * 
         * 如果全部选择Animation.ABSOLUTE,其实就是第二个构造函数。
         * 
         */
        
//        animation = new TranslateAnimation(
//            Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
//            Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
//        );
//        
//        animation.setDuration(1000);
        
     	animation = new RotateAnimation(15, 0, Animation.RELATIVE_TO_SELF, 0.2f, Animation.RELATIVE_TO_SELF,0f);
        animation.setDuration(1000);
        set.addAnimation(animation);

        LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
        ListView listView = getListView();   
        listView.setDivider(null);
        listView.setLayoutAnimation(controller);

3、ListView倒序显示加载动画

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:delay="30%"
        android:animationOrder="reverse"
        android:animation="@anim/slide_right" />
4、GridView随机加载显示动画

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:delay="0.5"
        android:animationOrder="random"
        android:animation="@anim/fade" />

5、GridView按照方向渐显式加载

<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:columnDelay="0.5"
        android:directionPriority="row"
        android:direction="right_to_left|bottom_to_top"
        android:animation="@anim/fade" />
6、GridView按照方向放大显式加载

<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:rowDelay="75%"
        android:columnDelay="0%"
        android:directionPriority="none"
        android:animation="@anim/wave_scale" />

7、TableRow 加载动画

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:delay="10%"
        android:animationOrder="reverse"
        android:animation="@anim/slide_right" />
</pre><pre name="code" class="html"><pre name="code" class="html"><layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:delay="10%"
        android:animation="@anim/slide_left" />

8、ProgressBar显示旋转动画

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <rotate
            android:drawable="@drawable/spinner_76_outer_holo"
            android:pivotX="50%"
            android:pivotY="50%"
            android:fromDegrees="0"
            android:toDegrees="1080" />
    </item>
    <item>
        <rotate
            android:drawable="@drawable/spinner_76_inner_holo"
            android:pivotX="50%"
            android:pivotY="50%"
            android:fromDegrees="720"
            android:toDegrees="0" />
    </item>
</layer-list>



 


现总结如下。以免日后遗忘~



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值