按钮滑动隐藏,停止滑动显示的动画
生活随笔
收集整理的這篇文章主要介紹了
按钮滑动隐藏,停止滑动显示的动画
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
想用tweenAnimation來做
res下新建anim文件夾,添加bottom_slide_in.xml和bottom_slide_out.xml
bottom_slide_in.xml
滑入動畫,從右邊往左邊移動,fromXDelta越大,移動距離越遠
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"android:duration="350"><translateandroid:fillAfter="true"android:fromXDelta="70%"android:fromYDelta="0%"android:toXDelta="0%"android:toYDelta="0%" /></set> 復制代碼bottom_slide_out.xml
滑出動畫,從展示位置往右邊移動,toXDelta越大,移動距離越遠
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"android:duration="350"><translateandroid:fillAfter="true"android:fromXDelta="0%"android:fromYDelta="0%"android:toXDelta="70%"android:toYDelta="0%" /></set> 復制代碼TestActivity.java
boolean scrollStateOld = true; //默認是展示狀態mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {@Overridepublic void onScrollStateChanged(RecyclerView recyclerView, int newState) {switch (newState) {case SCROLL_STATE_IDLE: //空閑狀態,停止滾動if (!scrollStateOld) {showBottomSVGA(R.anim.bottom_slide_in); //只show一次}break;case SCROLL_STATE_DRAGGING: //手指拖動,滾動狀態case SCROLL_STATE_SETTLING: //手指離開,慣性滾動狀態if (scrollStateOld) {showBottomSVGA(R.anim.bottom_slide_out); //只hide一次}break;}}@Overridepublic void onScrolled(RecyclerView recyclerView, int dx, int dy) {Log.e("zhen", "onScrolled: dx: " + dx + " dy: " + dy);}});private void showBottomSVGA(int animationStyle) {Animation animation = AnimationUtils.loadAnimation(getActivity(), animationStyle);animation.setFillAfter(true); //動畫結束后,保持動畫結束的狀態bottomSVGA.startAnimation(animation);scrollStateOld = !scrollStateOld; //取反} 復制代碼轉載于:https://juejin.im/post/5b92518d6fb9a05d171d1f29
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的按钮滑动隐藏,停止滑动显示的动画的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 理解马尔科夫过程
- 下一篇: jQuery 之 [ 动画 ]