1,Material Design简介
2,MaterialDesign主题Theme
3,android:elevation的使用
4,AndroidMaterialDesign动画之RippleDrawable
5,AndroidMaterialDesign动画之CircularReveal
6,AndroidMaterialDesign动画之Activity Transitions
7,AndroidMaterialDesign动画之Curved Motion
8,AndroidMaterialDesign动画之Animate View State Changes
view状态改变时执行的动画。
之前都写过选择器,其实跟这个一样一样的。
view的状态:
android:state_activated State value for StateListDrawable,
set when a view or its parent has been "activated"
meaning the user has currently marked it as being
of interest.
android:state_active State value for StateListDrawable.
display a check mark.
android:state_checked State identifier indicating that the object is
currently checked.
android:state_enabled State value for StateListDrawable, set when a view is enabled.
android:state_first State value for StateListDrawable.
android:state_focused State value for StateListDrawable, set when a view has input focus.
android:state_last State value for StateListDrawable.
android:state_middle State value for StateListDrawable.
android:state_pressed State value for StateListDrawable, set when the user is pressing down in a view.
android:state_selected State value for StateListDrawable, set when a view (or one of its parents)
is currently selected.
android:state_single State value for StateListDrawable.
android:state_window_focused
view状态改变的动画主要是两个类:
1,StateListAnimator 是个动画
2,AnimatedStateListDrawable 是个Drawable
也就是说StateListAnimator在res/anim中
AnimatedStateListDrawable在res/drawable中。
StateListAnimator
xml文件:你可以改成任意一种objectAnimator动画。 这里使用的是translationZ
<!-- animate the translationZ property of a view when pressed -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="@android:integer/config_shortAnimTime"
android:valueTo="2dp"
android:valueType="floatType"/>
<!-- you could have other objectAnimator elements
here for "x" and "y", or other properties -->
</set>
</item>
<item android:state_enabled="true"
android:state_pressed="false"
android:state_focused="true">
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="100"
android:valueTo="0"
android:valueType="floatType"/>
</set>
</item>
</selector>
代码中加载:1,加载动画。2 设置动画。
StateListAnimator stateLAnim = AnimatorInflater.loadStateListAnimator(this,R.anim.elevation);
tv_elevation.setStateListAnimator(stateLAnim);
AnimatedStateListDrawable
xml布局:这个效果有点意思
当你是pressed状态的时候animation-list正着走一遍,drawable使用最后一个。
当你是default状态时animation-list反着走一遍,drawable使用第一个。
res/drawable/myanimstatedrawable
<?xml version="1.0" encoding="utf-8"?>
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- provide a different drawable for each state -->
<item
android:id="@+id/pressed"
android:drawable="@drawable/btn_pressed"
android:state_pressed="true"/>
<!-- <item
android:id="@+id/focused"
android:drawable="@drawable/btn_focused"
android:state_focused="true"/> -->
<item
android:id="@id/default1"
android:drawable="@drawable/btn_default"/>
<!-- specify a transition -->
<transition
android:fromId="@+id/default1"
android:toId="@+id/pressed" >
<animation-list>
<item
android:drawable="@drawable/con_time_tk"
android:duration="500"/>
<item
android:drawable="@drawable/btn_default"
android:duration="500"/>
<item
android:drawable="@drawable/btn_focused"
android:duration="500"/>
<item
android:drawable="@drawable/btn_pressed"
android:duration="500"/>
<item
android:drawable="@drawable/con_time_xm"
android:duration="500"/>
<item
android:drawable="@drawable/con_time_tk"
android:duration="500"/>
</animation-list>
</transition>
</animated-selector>
xml文件作为控件的背景使用:
<TextView
android:id="@+id/tv_elevation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginRight="10dip"
android:background="@drawable/myanimstatedrawable"
android:clickable="true"
android:gravity="center"
android:elevation="5dip"
android:text="elevation10"
android:textSize="20sp" />