使用StateListAnimator讓Button動起來
讓原件狀態改變是通過StateListAnimator動畫集來改變View的狀態的 它可以使View在不同狀態下發生不同的變化
DEMO
實作
StateListAnimator.xml
在drawable 下新增一個 StateListAnimator.xml
valueTo可以依照喜好設定大一點讓他轉動角度變大一點
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<set>
<objectAnimator android:propertyName="rotationX"
android:duration="@android:integer/config_shortAnimTime"
android:valueTo="90"
android:valueType="floatType"/>
</set>
</item>
<item android:state_pressed="false">
<set>
<objectAnimator android:propertyName="rotationX"
android:duration="@android:integer/config_shortAnimTime"
android:valueTo="0"
android:valueType="floatType"/>
</set>
</item>
</selector>
activity_main
在你的
Button下 將下面的程式碼貼上 這樣點擊他就會有像Demo第一個的效果了
android:stateListAnimator="@drawable/StateListAnimator"
將Button改成線條
單單只有點擊動畫實在太醜了 將Button美化一下
- drawable 下新增一個
btn_loginsuccess.xml - 可以在自己修改要的寬度高度顏色
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="3dp" />
<stroke android:width="1dp"
android:color="#03A9F4" />
</shape>
activity_main.xmlButton下將background添加剛剛新增的xml皆可- 這樣就達到上面
DEMO第二個的效果了
android:background="@drawable/btn_loginsuccess"