//效果图就是这样的图,我是随便找的一张图,没办法我嫌录制GIF图,太麻烦了,反正就是这种效果。
//第一步 导入依赖
implementation 'jp.wasabeef:recyclerview-animators:2.2.7'
//第二步 适配器
//适配器 就是普普通通的适配器
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private List<String> mList;
private Context context;
public MyAdapter(List<String> mList, Context context) {
this.mList = mList;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View inflate = LayoutInflater.from(context).inflate(R.layout.layout_item, null);
ViewHolder holder = new ViewHolder(inflate);
return holder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.mText.setText(mList.get(position));
}
@Override
public int getItemCount() {
return mList.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public View rootView;
public TextView mText;
public ViewHolder(View rootView) {
super(rootView);
this.rootView = rootView;
this.mText = (TextView) rootView.findViewById(R.id.mText);
}
}
}
//第三步 Activity里使用
public class MainActivity extends AppCompatActivity {
private RecyclerView mRecy;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
mRecy = (RecyclerView) findViewById(R.id.mRecy);
List<String> mList=new ArrayList<>();
for (int i = 0; i < 300; i++) {
mList.add("Hello"+i);
}
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
mRecy.setLayoutManager(linearLayoutManager);
MyAdapter adapter = new MyAdapter(mList,this);
//渐变色动画
AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(adapter);
//放大动画,里面联合渐变色动画
ScaleInAnimationAdapter animationAdapter = new ScaleInAnimationAdapter(alphaAdapter);
//设置渐变色动画是否只走一次
alphaAdapter.setFirstOnly(false);
//设置放大动画是否只走一次
animationAdapter.setFirstOnly(false);
//设置渐变色动画的时间
alphaAdapter.setDuration(1000);
//设置放大动画的时间
animationAdapter.setDuration(1000);
//适配放大动画(放大动画里有渐变色动画)
mRecy.setAdapter(animationAdapter);
}
}
//Activity和适配器的布局也顺带粘贴上:
//Activity:activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hasee.a91zidingyiview.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/mRecy"
android:layout_width="match_parent"
android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>
//适配器布局:layout_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_marginTop="10dp"
android:background="#cc9c9c"
android:id="@+id/mText"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
//—————————————————————到这里就完事了———————————————————————–
//以下是一些动画的属性介绍:
Adapter的使用
1.使用
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
MyAdapter adapter = new MyAdapter();
recyclerView.setAdapter(new AlphaInAnimationAdapter(adapter));
2.高级功能
动画时长
MyAdapter adapter = new MyAdapter();
AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(adapter);
alphaAdapter.setDuration(1000);
recyclerView.setAdapter(alphaAdapter);
插值器
MyAdapter adapter = new MyAdapter();
AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(adapter);
alphaAdapter.setInterpolator(new OvershootInterpolator());
recyclerView.setAdapter(alphaAdapter);
是否仅显示一次动画效果
MyAdapter adapter = new MyAdapter();
AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(adapter);
scaleAdapter.setFirstOnly(false);
recyclerView.setAdapter(alphaAdapter);
复合动画
MyAdapter adapter = new MyAdapter();
AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(adapter);
recyclerView.setAdapter(new ScaleInAnimationAdapter(alphaAdapter));
//—————————————————————————-完————————————————————————–
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/118333.html