我实施了this library以使用swipe制作gmail效果。我已经测试并且工作正常,但它在某些设备上根本没有滑动。任何人遇到类似的问题和解决这个问题的方法??
PlayersAdapter.class
public class PlayersAdapter extends RecyclerSwipeAdapter<PlayersAdapter.clientViewHolder> {
protected SwipeItemRecyclerMangerImpl mItemManger = new SwipeItemRecyclerMangerImpl(this);
private Context context;
private ArrayList<User> players;
private PlayersFragment fragment;
public PlayersAdapter(Context context, ArrayList<User> players, PlayersFragment fragment) {
this.context = context;
this.players = players;
this.fragment = fragment;
}
@Override
public clientViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == Constants.ACTIVE_CONSUMER) {
return new clientViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.active_client_item, parent, false), Constants.ACTIVE_CONSUMER);
} else {
return new clientViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.invited_client_item, parent, false), Constants.INVITED_CONSUMER);
}
}
@Override
public int getItemViewType(int position) {
if (players.get(position).getStatus().equals(Constants.STATUS_INVITED)) {
return Constants.INVITED_CONSUMER;
}
return Constants.ACTIVE_CONSUMER;
}
@Override
public void onBindViewHolder(final clientViewHolder viewHolder, final int position) {
final User player = players.get(position);
int screenWidth = UIUtils.getScreenWidth((Activity) context);
int screen = screenWidth - screenWidth / 4;
if (player.getStatus().equals(Constants.STATUS_INVITED)) {
viewHolder.rlRemove.getLayoutParams().width = screen / 3;
viewHolder.rlPlayerEdit.getLayoutParams().width = screen / 3;
viewHolder.rlPlayerEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
viewHolder.swipeLayout.close();
editClient(player.getId());
}
});
viewHolder.rlSendAnotherInvitation.getLayoutParams().width = screen / 3;
viewHolder.rlSendAnotherInvitation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
viewHolder.swipeLayout.close();
} else {
viewHolder.swipeLayout.close();
}
}
});
viewHolder.rlPlayerOptions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (viewHolder.swipeLayout.getOpenStatus() == SwipeLayout.Status.Open) {
viewHolder.swipeLayout.close();
} else {
viewHolder.swipeLayout.open();
AnimationUtils.setFadeInAnimation(viewHolder.rlRemove, AnimationUtils.DELAY_DURATION);
AnimationUtils.setFadeInAnimation(viewHolder.rlPlayerEdit, AnimationUtils.DELAY_DURATION * 2);
AnimationUtils.setFadeInAnimation(viewHolder.rlSendAnotherInvitation, AnimationUtils.DELAY_DURATION * 3);
}
}
});
} else {
viewHolder.rlRemove.getLayoutParams().width = screen;
if (player.getImage() == null) {
viewHolder.ivPlayerAvatar.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.user_ic));
} else {
final ProgressBar progressView = viewHolder.progressBar;
progressView.setVisibility(View.VISIBLE);
progressView.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.dark_blue), PorterDuff.Mode.SRC_IN);
Picasso.with(context)
.load(player.getImage().getSize128())
.fit()
.transform(new RoundedTransformation(15, 0))
.error(ContextCompat.getDrawable(context, R.drawable.user_ic))
.into(viewHolder.ivPlayerAvatar, new Callback() {
@Override
public void onSuccess() {
progressView.setVisibility(View.GONE);
}
@Override
public void onError() {
progressView.setVisibility(View.GONE);
}
});
}
viewHolder.rlPlayerOptions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (viewHolder.swipeLayout.getOpenStatus() == SwipeLayout.Status.Open) {
viewHolder.swipeLayout.close();
} else {
viewHolder.swipeLayout.open();
AnimationUtils.setFadeInAnimation(viewHolder.rlRemove, AnimationUtils.DELAY_DURATION);
}
}
});
viewHolder.clientRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
viewHolder.rlRemove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
viewHolder.swipeLayout.close();
}
});
viewHolder.tvPlayerFullName.setText(players.get(position).getFullName());
viewHolder.swipeLayout.setShowMode(SwipeLayout.ShowMode.PullOut);
viewHolder.swipeLayout.addDrag(SwipeLayout.DragEdge.Right, viewHolder.swipeLayout.findViewById(R.id.options));
viewHolder.swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
@Override
public void onClose(SwipeLayout layout) {
}
@Override
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
}
@Override
public void onStartOpen(SwipeLayout layout) {
}
@Override
public void onOpen(SwipeLayout layout) {
}
@Override
public void onStartClose(SwipeLayout layout) {
}
@Override
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
}
});
mItemManger.bindView(viewHolder.itemView, position);
}
@Override
public int getItemCount() {
return players.size();
}
@Override
public int getSwipeLayoutResourceId(int position) {
return R.id.swipe;
}
public class clientViewHolder extends RecyclerView.ViewHolder {
/**
* Common UI Elements
*/
private SwipeLayout swipeLayout;
private TextView tvPlayerFullName;
private RelativeLayout rlRemove;
private RelativeLayout rlPlayerOptions;
private ProgressBar progressBar;
private ImageView ivPlayerAvatar;
private RelativeLayout clientRow;
/**
* Invited Consumer UI Elements
*/
private RelativeLayout rlPlayerEdit;
private RelativeLayout rlSendAnotherInvitation;
public clientViewHolder(View itemView, int status) {
super(itemView);
tvPlayerFullName = (TextView) itemView.findViewById(R.id.tvClientFullName);
swipeLayout = (SwipeLayout) itemView.findViewById(R.id.swipe);
rlPlayerOptions = (RelativeLayout) itemView.findViewById(R.id.ivClientOptions);
rlRemove = (RelativeLayout) itemView.findViewById(R.id.rlRemove);
clientRow = (RelativeLayout) itemView.findViewById(R.id.clientRow);
ivPlayerAvatar = (ImageView) itemView.findViewById(R.id.civClientAvatar);
progressBar = (ProgressBar) itemView.findViewById(R.id.progressBar);
if (status == Constants.INVITED_CONSUMER) {
rlPlayerEdit = (RelativeLayout) itemView.findViewById(R.id.rlEdit);
rlSendAnotherInvitation = (RelativeLayout) itemView.findViewById(R.id.rlSendAnotherInvitation);
}
}
}
}
PlayersActivity.class
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST, R.drawable.divider));
mAdapter = new PlayersAdapter(context, players, PlayersFragment.this);
(mAdapter).setMode(Attributes.Mode.Multiple);
recyclerView.setAdapter(mAdapter);