Effect:
Original view: https://blog.csdn.net/calvin_zhou/article/details/79253709
After a general App refresh, it will show how much content or update has been added. It is common for news or live broadcast. So, how to achieve this effect?
Pull down refresh to get the latest data of the server. The size of the data collection will be compared with the original. The server will complete the work of getting the required value or the number of updates.
The next step is to display data through animation, which can be realized by itself. This time, the third-party class library ViewAnimator is used to realize cool special effects, and SmartRefresh is used to refresh.
Implementation steps:
1. Add dependency
//Refresh - SmartRefreshLayout compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.4-7' //Smooth Android animation library compile 'com.github.florent37:viewanimator:1.0.5@aar'
2.activity Code:
public class MainActivity extends AppCompatActivity { @BindView(R.id.rl_top_toast) RelativeLayout rlTopToast; @BindView(R.id.tv_toast) TextView tvToast; @BindView(R.id.refreshLayout) SmartRefreshLayout refreshLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); setListener(); } private void setListener() { refreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(RefreshLayout refreshlayout) { showToast(new Random().nextInt(10) + 1); refreshlayout.finishRefresh(); } }); } private void showToast(int num) { // Use String.format here to assign a value to a single placeholder tvToast.setText(String.format(getResources().getString(R.string.live_toast), num + "")); rlTopToast.setVisibility(View.VISIBLE); ViewAnimator.animate(rlTopToast) .newsPaper() .duration(2000) .start() .onStop(new AnimationListener.Stop() { @Override public void onStop() { ViewAnimator.animate(rlTopToast) .bounceOut() .duration(2000) .start(); } }); } }
3. The layout file is as follows:
<?xml version="1.0" encoding="utf-8"?> <com.scwang.smartrefresh.layout.SmartRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/refreshLayout" android:layout_width="match_parent" android:layout_height="match_parent" app:srlEnableLoadmore="true"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World!" /> <RelativeLayout android:id="@+id/rl_top_toast" android:layout_width="match_parent" android:layout_height="30dp" android:background="#D6E9F6" android:visibility="gone"> <TextView android:id="@+id/tv_toast" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="@string/live_toast" android:textColor="#3393D5" android:textSize="12sp" /> </RelativeLayout> </RelativeLayout> </com.scwang.smartrefresh.layout.SmartRefreshLayout>
% 1$s new information has been recommended for you < / String >