SwipeListView运行良好,但有时会遇到一个问题,即如果我们点击“swipeFrontView”的相应位置,应点击“swipeBackView”项目。请帮助我,并提前致谢。 我的xml代码如下:
activity_home.xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
<com.fortysevendeg.android.swipelistview.SwipeListView
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="@+id/lstRequests"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:listSelector="#00000000"
swipe:swipeBackView="@+id/back"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeDrawableChecked="@drawable/choice_selected"
swipe:swipeDrawableUnchecked="@drawable/choice_unselected"
swipe:swipeFrontView="@+id/front"
swipe:swipeMode="left" >
</com.fortysevendeg.android.swipelistview.SwipeListView
</RelativeLayout>
package_row.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/back" <===
style="@style/ListBackContent"
android:layout_width="wrap_content"
android:layout_height="110dp"
android:tag="back" >
<LinearLayout
android:id="@+id/backshowportion"
style="@style/ListBackContent"
android:layout_width="250dp"
android:layout_height="110dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/bg"
android:gravity="right|center" >
<TextView
..... />
<TextView
..... />
<TextView
...../>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/front" <===
style="@style/ListFrontContent"
android:layout_width="match_parent"
android:layout_height="110dp"
android:orientation="vertical"
android:tag="front" >
<TextView
..... />
<TextView
..... />
<TextView
..... />
<TextView
..... />
</RelativeLayout>
</FrameLayout>
以及类别代码的一部分如下:
protected void onCreate(Bundle savedInstanceState)
{
swipeListView=(SwipeListView)findViewById(R.id.lstRequests);
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,MenuItem item)
{
return false;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu)
{
return false;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu)
{
return false;
}
});
}
}
public void onStart()
{
super.onStart();
listner();
}
private void listner()
{
swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener()
{
@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 onOpened(int position, boolean toRight)
{
}
@Override
public void onMove(int position, float x)
{
}
@Override
public void onListChanged()
{
}
@Override
public void onLastListItem()
{
}
@Override
public void onFirstListItem()
{
}
@Override
public void onDismiss(int[] reverseSortedPositions)
{
}
@Override
public void onClosed(int position, boolean fromRight)
{
}
@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 onChoiceStarted()
{
}
@Override
public void onChoiceEnded()
{
}
@Override
public void onChoiceChanged(int arg0, boolean arg1)
{
}
@Override
public int onChangeSwipeMode(int arg0)
{
return 0;
}
});
答案 0 :(得分:5)
我修改了package_row.xml的FrontView,使RlativeLayout可点击如下,并且现在正常工作,。
<RelativeLayout
android:id="@+id/front"
style="@style/ListFrontContent"
android:layout_width="match_parent"
android:layout_height="110dp"
android:orientation="vertical"
android:clickable="true"
android:tag="front" >