xrecyclerview展示加适配器和动画

//mainactivy
public class MainActivity extends AppCompatActivity implements MainView {

private XRecyclerView xrecyclerview;
private NewAdapter newAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    xrecyclerview = findViewById(R.id.xrecyclerview);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
    xrecyclerview.setLayoutManager(gridLayoutManager);


    newAdapter = new NewAdapter(this);
    xrecyclerview.setAdapter(newAdapter);

mainPresenterlml = new MainPresenterlml(this, new MainModelml());
    mainPresenterlml.dodata();


    xrecyclerview.setLoadingMoreEnabled(true);
    xrecyclerview.setLoadingListener(new XRecyclerView.LoadingListener() {
        @Override
        public void onRefresh() {

        }

        @Override
        public void onLoadMore() {

        }
    });
    MainPresenterlml mainPresenterlml = new MainPresenterlml(new MainModelml(), this);
    mainPresenterlml.doData();


}

@Override
public void success(String data) {
    NewBean bean = new Gson().fromJson(data, NewBean.class);
    newAdapter.setData(bean.getResult());


}

@Override
public void fail() {

}

@Override
protected void onDestroy() {
    super.onDestroy();
}

}

//适配器====

public class NewAdapter extends RecyclerView.Adapter {

private Context context;
private List result=new ArrayList<>();

public NewAdapter(Context context){
    this.context=context;

}

public  void setData(List result) {
    this.result=result;
    notifyDataSetChanged();
}


@NonNull
@Override
public NewAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = View.inflate(context, R.layout.new_item, null);
    MyViewHolder myViewHolder = new MyViewHolder(view);
    return myViewHolder;
}

@Override
public void onBindViewHolder(@NonNull NewAdapter.MyViewHolder myViewHolder, int i) {
        myViewHolder.textView.setText(result.get(i).getName());
    Glide.with(context).load(result.get(i).getImageUrl())
            .error(R.drawable.ic_launcher_background)
            .placeholder(R.drawable.ic_launcher_background)
            .into(myViewHolder.imageView);
}

@Override
public int getItemCount() {
    return result.size();
}

public class MyViewHolder extends RecyclerView.ViewHolder {
    TextView textView;
    ImageView imageView;
    public MyViewHolder(@NonNull View itemView) {
        super(itemView);
        imageView=(ImageView) itemView.findViewById(R.id.imageview);
        textView=(TextView) itemView.findViewById(R.id.textview);

    }
}

}

//动画

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    image = findViewById(R.id.immage);
    button1 = findViewById(R.id.button1);

    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(image,"translationY",0,500);
            ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(image,"rotation",0,720);
            AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.play(objectAnimator1).with(objectAnimator);
            animatorSet.setDuration(4000);
            animatorSet.start();
        }
    });
}

}

你可能感兴趣的:(xrecyclerview展示加适配器和动画)