try to fix #74

This commit is contained in:
daimajia 2015-01-24 10:22:39 +08:00
parent a9cc7d28eb
commit a92a2cdae7
3 changed files with 50 additions and 66 deletions

View File

@ -14,6 +14,7 @@ import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import com.daimajia.swipe.SwipeLayout;
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
import com.daimajia.swipedemo.adapter.ListViewAdapter;
@ -43,7 +44,7 @@ public class ListViewExample extends Activity {
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(mContext, "Click", Toast.LENGTH_SHORT).show();
((SwipeLayout)(mListView.getChildAt(position - mListView.getFirstVisiblePosition()))).open(true);
}
});
mListView.setOnTouchListener(new View.OnTouchListener() {

View File

@ -1,57 +1,53 @@
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.daimajia.swipe.SwipeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.daimajia.swipe.SwipeLayout
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipe"
android:layout_height="wrap_content">
<LinearLayout
android:background="#FF5534"
android:tag="Bottom3"
android:weightSum="10"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="80dp">
<ImageView
android:id="@+id/trash"
android:src="@drawable/trash"
android:layout_weight="1"
android:layout_width="27dp"
android:layout_height="30dp" />
<TextView
android:text="Delete Item?"
android:textSize="17sp"
android:textColor="#fff"
android:layout_weight="5"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:id="@+id/delete"
android:textColor="#FF5534"
android:background="#ffffff"
android:text="Yes,Delete"
android:layout_weight="4"
android:layout_width="0dp"
android:layout_height="40dp" />
</LinearLayout>
<LinearLayout
android:background="#FF5534"
android:tag="Bottom3"
android:weightSum="10"
android:gravity="center"
<LinearLayout
android:padding="10dp"
android:background="@drawable/item_selector"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/position"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:tag="Hover"
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. "
android:layout_width="match_parent"
android:layout_height="80dp">
<ImageView
android:id="@+id/trash"
android:src="@drawable/trash"
android:layout_weight="1"
android:layout_width="27dp"
android:layout_height="30dp" />
<TextView
android:text="Delete Item?"
android:textSize="17sp"
android:textColor="#fff"
android:layout_weight="5"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:id="@+id/delete"
android:textColor="#FF5534"
android:background="#ffffff"
android:text="Yes,Delete"
android:layout_weight="4"
android:layout_width="0dp"
android:layout_height="40dp" />
</LinearLayout>
<LinearLayout
android:padding="10dp"
android:background="@drawable/item_selector"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/position"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:tag="Hover"
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. "
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</com.daimajia.swipe.SwipeLayout>
</LinearLayout>
android:layout_height="match_parent" />
</LinearLayout>
</com.daimajia.swipe.SwipeLayout>

View File

@ -786,21 +786,8 @@ public class SwipeLayout extends FrameLayout {
if(touching != null)
touching.setPressed(true);
return true;
case MotionEvent.ACTION_MOVE:{
if(sX == -1 || sY == -1){
// Trick:
// When in nested mode, we need to send a constructed ACTION_DOWN MotionEvent to mDragHelper, to help
// it initialize itself.
event.setAction(MotionEvent.ACTION_DOWN);
mDragHelper.processTouchEvent(event);
parent.requestDisallowInterceptTouchEvent(true);
sX = event.getRawX();
sY = event.getRawY();
return true;
}
float distanceX = event.getRawX() - sX;
float distanceY = event.getRawY() - sY;
float angle = Math.abs(distanceY / distanceX);