步驟:
- 基于RecyclerView
- 數(shù)據(jù)默認(rèn)顯示最后一個(gè)
- 監(jiān)聽 RecyclerView Scroll 方法
ArrayList<String> sts = new ArrayList<>();
for (int i = 0; i < 50; i++) {
sts.add("第 " + i + " 條數(shù)據(jù)");
}
mRecyclerView.setHasFixedSize(true);
final ScrollSpeedLinearLayoutManger layoutManager = new ScrollSpeedLinearLayoutManger(this);
mRecyclerView.setLayoutManager(layoutManager);
mItemAdapter = new ItemAdapter(this, sts);
mRecyclerView.setAdapter(mItemAdapter);
mRecyclerView.smoothScrollToPosition(mItemAdapter.getItemCount() - 1);
mTxtNoReadingType.setText("^ 10 條未讀");
mTxtNoReadingType.startAnimation(AnimationUtils.loadAnimation(this, R.anim.in_x));
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int position = layoutManager.findFirstVisibleItemPosition();
Log.i(TAG, "onScrolled: position================" + position);
if (mItemAdapter != null && position != 0) {
int count = mItemAdapter.getItemCount();
if(mTxtNoReadingType.getVisibility()==View.VISIBLE){
if (count - position == 10) {
mTxtNoReadingType.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.out_x));
mTxtNoReadingType.setVisibility(View.INVISIBLE);
}
}
}
}
});
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500">
<translate
android:fromXDelta="100%"
android:toXDelta="0%"
/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500">
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
/>
</set>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者