#java #android #listview
Есть ListView в котором есть 1000 элементов и при быстрой прокрутке списка возникает эффект как у колеса машины, сначала в одну сторону прокрутка идет , а потом обратно, хотя по факту он в нужную сторону крутится, каким образом можно избавиться от этого эффекта? Возможно для большого количества элементов в списке нужен другой адаптер ? ListViewAdapter.java public class ContactListAdapter extends BaseAdapter { private Context context; private static final String TAG = "ContactListAdapter"; ArrayListlist; private LayoutInflater layoutInflater; private ViewHolder preHolder; private ViewHolder secondHold; public ContactListAdapter(Context context, ContactList contactList) { this.context = context; list = contactList; layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public void setList(ArrayList list) { this.list = list; } public static class ViewHolder { private View rootView; private TextView tvName; private TextView tvInitials; private ImageView ivAvatart; private ImageView ivStatus; private RelativeLayout relativeLayoutParent; private RelativeLayout relativeLayoutMain; private RelativeLayout onlineButtonContainer; private RelativeLayout timeoutButtonContainer; private RelativeLayout relativeLayout_exit_buuton_conteiner; private RelativeLayout relativeLayout_icon_phone; private String contactName; private boolean isShow; private ContactCaling contactCaling; } @Override public View getView(final int position, final View convertView, final ViewGroup parent) { final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); holder.rootView = convertView; LayoutInflater layoutInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); holder.rootView = layoutInflater.inflate(R.layout.main_contact_list_item, null); holder.tvName = (TextView) holder.rootView.findViewById(R.id.textView_contact_name); holder.tvInitials = (TextView) holder.rootView.findViewById(R.id.textView_contact_initials); holder.ivAvatart = (ImageView) holder.rootView.findViewById(R.id.imageView_contact_avatar); holder.ivStatus = (ImageView) holder.rootView.findViewById(R.id.imageView_status); holder.relativeLayoutParent = (RelativeLayout) holder.rootView.findViewById(R.id.relativeLayout_parent); holder.relativeLayoutMain = (RelativeLayout) holder.rootView.findViewById(R.id.relativeLayout_main); holder.onlineButtonContainer = (RelativeLayout) holder.rootView.findViewById(R.id.relativeLayout_call_button_container); holder.relativeLayout_icon_phone = (RelativeLayout) holder.rootView.findViewById(R.id.relativeLayout_icon_phone); holder.timeoutButtonContainer = (RelativeLayout) holder.rootView.findViewById(R.id.relativeLayout_call_busy_button_container); holder.relativeLayout_exit_buuton_conteiner = (RelativeLayout) holder.rootView.findViewById(R.id.relativeLayout_exit_buuton_conteiner); /**-------------Item listener---------------**/ holder.relativeLayoutParent.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (preHolder == null || (secondHold != null && secondHold.equals(holder))) { if (MyApplication.isOnline()) { int buttonTranslation = -holder.onlineButtonContainer.getLayoutParams().width + 2; holder.onlineButtonContainer .animate() .translationX(buttonTranslation) .setDuration(350); secondHold = null; } else { int buttonTranslation = -holder.timeoutButtonContainer.getLayoutParams().width + 2; holder.timeoutButtonContainer .animate() .translationX(buttonTranslation) .setDuration(350); secondHold = null; } } if (preHolder != null) { if (MyApplication.isOnline()) { int translate = preHolder.onlineButtonContainer.getLayoutParams().width; preHolder.relativeLayoutMain .animate() .translationX(0) .setDuration(350); preHolder.onlineButtonContainer .animate() .translationX(translate) .setDuration(350); } else { int translate = preHolder.timeoutButtonContainer.getLayoutParams().width; preHolder.relativeLayoutMain .animate() .translationX(0) .setDuration(350); preHolder.timeoutButtonContainer .animate() .translationX(translate) .setDuration(350); } } if (preHolder != null) { preHolder = null; } else { preHolder = holder; } secondHold = holder; } }); holder.isShow = false; holder.rootView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.contact = (Contact) getItem(position); holder.contactName = holder.contact.getDisplayName(); holder.tvName.setText(holder.contactName); setIcons(position, holder); return holder.rootView; } @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return position; } }
Ответы
Ответ 1
Нужно сделать так, что бы частота обновления экрана была различна с частотой прокручивания элементов списка. Наверно можно уменьшить скорость скрола ListView listView.setFriction(ViewConfiguration.getScrollFriction() * FRICTION_SCALE_FACTOR)
Комментариев нет:
Отправить комментарий