SwipeRefreshLayout: Swipe progress animation

前端 未结 2 1233
无人及你
无人及你 2020-12-14 11:37

I\'m quite new to android and I\'m exploring the sample code on google website. The code I\'m on currently is the SwipeRefreshLayout: http://developer.android.com/samples/Sw

相关标签:
2条回答
  • 2020-12-14 12:04

    although you can't change it, you can still hide it and then display your own once triggered :-)

    SwipeRefreshLayout swiperefresh = (SwipeRefreshLayout)root.findViewById(R.id.swiperefresh);
    swiperefresh.setOnRefreshListener(this);
    swiperefresh.setColorSchemeColors(0,0,0,0);
    swiperefresh.setProgressBackgroundColor(android.R.color.transparent); 
    

    Notes:

    • in eclipse you have to add @SuppressLint("ResourceAsColor") to compile this.

    • you still need to call setRefreshing(false) at an appropriate point in time else onRefresh doesn't trigger again.

    0 讨论(0)
  • 2020-12-14 12:13

    You can't change the animation.

    In SwipeRefreshLayout you can't customize much; I believe this is an attempt of Google to get developers stick to common patterns. What you can style are the four colors of the animation, specified with setColorScheme().

    SwipeRefreshLayout takes care to show its predefined animation at its top for you. This can be when canChildScrollUp() returns false and user 'pulls down', or when you set setRefreshing(true). Turn off the animation with setRefreshing(false). Put your logic in the method onRefreshing() of the listener. Override canChildScrollUp() if you put something that is not a ListView in your SwipeRefreshLayout. You should be good to go from here.

    0 讨论(0)
提交回复
热议问题