当我将它插入到recyclerView时,如何动画物品recyclerview

时间:2016-01-29 14:32:13

标签: android android-animation android-recyclerview

我有一个RecyclerView,当我将其插入RecyclerView时,我希望为插入的Item设置动画,但前提是它是可见的。如果该项目在屏幕中不可见,请勿对其进行动画处理 我该怎么办?

这是我的适配器:

public class RunningAppAdapter extends RecyclerView.Adapter<RunningAppAdapter.ContactViewHolder> {

    private List<AppInfo> appList;
    public static Context contextMain;
    public static Picasso mPicasso;
    private boolean[] itemChecks;

    public RunningAppAdapter(List<AppInfo> appList,Context context) {
        this.appList = appList;
        RunningAppAdapter.contextMain = context;
        Picasso.Builder builder = new Picasso.Builder(contextMain);
        builder.addRequestHandler(new AppIconRequestHandler(contextMain));
        itemChecks = new boolean [1000];
        Arrays.fill(itemChecks, true);
        mPicasso = builder.build();
    }

    public RunningAppAdapter(Context context) {
        this.appList = new ArrayList<AppInfo>();
        RunningAppAdapter.contextMain = context;
        Picasso.Builder builder = new Picasso.Builder(contextMain);
        builder.addRequestHandler(new AppIconRequestHandler(contextMain));

        itemChecks = new boolean [1000];
        Arrays.fill(itemChecks, true);
        mPicasso = builder.build();
    }

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


    public void removeFirstItems(int count) {
        for (int i=0; i<count; i++) 
            appList.remove(0);
        notifyDataSetChanged();
    }

    public void insertItem(int count, AppInfo object) {
        appList.add(count,object);
        notifyItemInserted(count);
    }


    @Override
    public void onBindViewHolder(ContactViewHolder appViewHolder, final int position) {


        AppInfo appInfo = appList.get(position);
        appViewHolder.appName.setText(appInfo.appName);
        appViewHolder.appPackage.setText(appInfo.appPackage);
        appViewHolder.appMemUsed.setText(appInfo.appMemUsed);
        appViewHolder.appMemUsed.setOnCheckedChangeListener(null);
        appViewHolder.appMemUsed.setChecked(itemChecks[position]);
        appViewHolder.appMemUsed.setOnCheckedChangeListener(new OnCheckedChangeListener() {         
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {                                
                itemChecks[position] = isChecked;
            }
        });
        mPicasso.load(AppIconRequestHandler.SCHEME_APP_ICON + ":" + appInfo.appPackage.split(":")[0]).placeholder(R.drawable.ic_launcher).into(appViewHolder.appDrawable);       
    }

    @Override
    public ContactViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
            View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.custom_item_app, viewGroup, false);
            ContactViewHolder app = new ContactViewHolder(itemView);
            return app;

    }

    public static class ContactViewHolder extends RecyclerView.ViewHolder {

        protected TextView appName;
        protected TextView appPackage;
        protected ImageView appDrawable;
        protected AppCompatCheckBox appMemUsed;
        protected CardView item_card;

        public ContactViewHolder(View v) {
            super(v);

            contextMain = v.getContext();
            appName =  (TextView) v.findViewById(R.id.txtAppName);
            appPackage = (TextView)  v.findViewById(R.id.txtAppPackage);
            appDrawable = (ImageView) v.findViewById(R.id.imgAppIcon);
            appMemUsed = (AppCompatCheckBox) v.findViewById(R.id.chboxFree);
            item_card = (CardView) v.findViewById(R.id.card_view);

            v.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    Log.i("Click", "Element"+getLayoutPosition() +"click." +appName.getText().toString());
                    boolean checkBoxState = !appMemUsed.isChecked();
                    appMemUsed.setChecked(checkBoxState);   
                }
            });       
        }

    } 

}

0 个答案:

没有答案