我正在使用 android 中的 swipelistview,我需要在列表视图中实现 onClick 以刷出列表项。我在 OnclickfrontView 中使用了 openanimate 方法。但我的输出结果是相反的。我从右到左而不是从左到右获得视图。我使用的库是https://github.com/47deg/android-swipelistview
. swipelistview 的 xml 布局是
android:id="@+id/search_screen_listview_sharedData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginTop="0dp"
android:cacheColorHint="#00000000"
android:background="@color/white"
android:divider="@color/sliding_menu_listview_divider"
android:dividerHeight="0.2dp"
android:fadingEdgeLength="0dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:listSelector="@color/transparent"
swipe:swipeFrontView="@+id/front"
swipe:swipeBackView="@+id/back"
swipe:swipeOpenOnLongPress="false"
swipe:swipeActionLeft="reveal"
swipe:swipeActionRight="reveal"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeDrawableChecked="@color/sliding_menu_selection_blue"
swipe:swipeDrawableUnchecked="@color/white"
swipe:swipeOffsetLeft="200dp"
swipe:swipeOffsetRight="70dp"
swipe:swipeMode="right" />
供您参考的示例代码是
swipeListView = (SwipeListView) view
.findViewById(R.id.listview_sharedData);
swipeFrontView = (View) view.findViewById(R.id.front);
if (Build.VERSION.SDK_INT >= 11) {
swipeListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
swipeListView
.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
@Override
public void onItemCheckedStateChanged(ActionMode mode,
int position, long id, boolean checked) {
mode.setTitle("Selected ("
+ swipeListView.getCountSelected() + ")");
}
@Override
public void onDestroyActionMode(ActionMode mode) {
swipeListView.unselectedChoiceStates();
}
@Override
public boolean onActionItemClicked(ActionMode mode,
android.view.MenuItem item) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onCreateActionMode(ActionMode mode,
android.view.Menu menu) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onPrepareActionMode(ActionMode mode,
android.view.Menu menu) {
// TODO Auto-generated method stub
return false;
}
});
}
swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() {
@Override
public void onOpened(int position, boolean toRight) {
}
@Override
public void onClosed(int position, boolean fromRight) {
}
@Override
public void onListChanged() {
}
@Override
public void onMove(int position, float x) {
}
@Override
public void onStartOpen(int position, int action, boolean right) {
Log.d("swipe", String.format("onStartOpen %d - action %d",
position, action));
}
@Override
public void onStartClose(int position, boolean right) {
Log.d("swipe", String.format("onStartClose %d", position));
}
@Override
public void onClickFrontView(int position) {
Log.d("swipe", String.format("onClickFrontView %d", position));
swipeListView.openAnimate(position);
}
@Override
public void onClickBackView(int position) {
Log.d("swipe", String.format("onClickBackView %d", position));
//swipeListView.closeAnimate(position);
}
@Override
public void onDismiss(int[] reverseSortedPositions) {
/*
* for (int position : reverseSortedPositions) {
* data.remove(position); } adapter.notifyDataSetChanged();
*/
}
});
if (Constant.List != null) {
if (Constant.List.size() > 0) {
swipeListView.setAdapter(new CustomContentListAdapter(
getActivity(), Constant.List, true));
}
}
return view;
}
当我单击列表视图项目时,请帮助我如何实现从左到右的 swipview。我为此苦苦挣扎了一周,但仍然没有得到好的解决方案。
public void openAnimate(int position) {
touchListener.openAnimate(position);
}
protected void openAnimate(int position) {
openAnimate(
swipeListView.getChildAt(
position - swipeListView.getFirstVisiblePosition())
.findViewById(swipeFrontView), position);
}
private void openAnimate(View view, int position) {
if (!opened.get(position)) {
generateRevealAnimate(view, true, false, position);
}
}
private void generateRevealAnimate(final View view, final boolean swap,
final boolean swapRight, final int position) {
int moveTo = 0;
if (opened.get(position)) {
if (!swap) {
moveTo = openedRight.get(position) ? (int) (viewWidth - rightOffset)
: (int) (-viewWidth + leftOffset);
}
} else {
if (swap) {
moveTo = swapRight ? (int) (viewWidth - rightOffset)
: (int) (-viewWidth + leftOffset);
}
}
animate(view).translationX(moveTo).setDuration(animationTime)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
swipeListView.resetScrolling();
if (swap) {
boolean aux = !opened.get(position);
opened.set(position, aux);
if (aux) {
swipeListView.onOpened(position, swapRight);
openedRight.set(position, swapRight);
} else {
swipeListView.onClosed(position,
openedRight.get(position));
}
}
resetCell();
}
});
}
private void resetCell() {
if (downPosition != ListView.INVALID_POSITION) {
if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
backView.setVisibility(View.VISIBLE);
}
frontView.setClickable(opened.get(downPosition));
frontView.setLongClickable(opened.get(downPosition));
frontView = null;
backView = null;
downPosition = ListView.INVALID_POSITION;
}
}