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

来源:互联网 发布:淘宝旺旺在线生成代码 编辑:程序博客网 时间:2024/06/11 21:56

今天研究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
原创粉丝点击