Skip to content

Commit a92a2cd

Browse files
committed
try to fix #74
1 parent a9cc7d2 commit a92a2cd

File tree

3 files changed

+50
-66
lines changed

3 files changed

+50
-66
lines changed

demo/src/main/java/com/daimajia/swipedemo/ListViewExample.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.widget.ListView;
1515
import android.widget.Toast;
1616

17+
import com.daimajia.swipe.SwipeLayout;
1718
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
1819
import com.daimajia.swipedemo.adapter.ListViewAdapter;
1920

@@ -43,7 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
4344
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
4445
@Override
4546
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
46-
Toast.makeText(mContext, "Click", Toast.LENGTH_SHORT).show();
47+
((SwipeLayout)(mListView.getChildAt(position - mListView.getFirstVisiblePosition()))).open(true);
4748
}
4849
});
4950
mListView.setOnTouchListener(new View.OnTouchListener() {
+48-52
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,53 @@
11
<?xml version="1.0" encoding="utf-8" ?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<com.daimajia.swipe.SwipeLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:id="@+id/swipe"
35
android:layout_width="match_parent"
4-
android:layout_height="match_parent">
5-
<com.daimajia.swipe.SwipeLayout
6-
xmlns:swipe="http://schemas.android.com/apk/res-auto"
7-
android:id="@+id/swipe"
8-
android:layout_width="match_parent"
9-
android:layout_height="wrap_content">
6+
android:layout_height="wrap_content">
107

11-
<LinearLayout
12-
android:background="#FF5534"
13-
android:tag="Bottom3"
14-
android:weightSum="10"
15-
android:gravity="center"
16-
android:layout_width="match_parent"
17-
android:layout_height="80dp">
18-
<ImageView
19-
android:id="@+id/trash"
20-
android:src="@drawable/trash"
21-
android:layout_weight="1"
22-
android:layout_width="27dp"
23-
android:layout_height="30dp" />
24-
<TextView
25-
android:text="Delete Item?"
26-
android:textSize="17sp"
27-
android:textColor="#fff"
28-
android:layout_weight="5"
29-
android:layout_width="0dp"
30-
android:layout_height="wrap_content" />
31-
<Button
32-
android:id="@+id/delete"
33-
android:textColor="#FF5534"
34-
android:background="#ffffff"
35-
android:text="Yes,Delete"
36-
android:layout_weight="4"
37-
android:layout_width="0dp"
38-
android:layout_height="40dp" />
39-
</LinearLayout>
8+
<LinearLayout
9+
android:background="#FF5534"
10+
android:tag="Bottom3"
11+
android:weightSum="10"
12+
android:gravity="center"
13+
android:layout_width="match_parent"
14+
android:layout_height="80dp">
15+
<ImageView
16+
android:id="@+id/trash"
17+
android:src="@drawable/trash"
18+
android:layout_weight="1"
19+
android:layout_width="27dp"
20+
android:layout_height="30dp" />
21+
<TextView
22+
android:text="Delete Item?"
23+
android:textSize="17sp"
24+
android:textColor="#fff"
25+
android:layout_weight="5"
26+
android:layout_width="0dp"
27+
android:layout_height="wrap_content" />
28+
<Button
29+
android:id="@+id/delete"
30+
android:textColor="#FF5534"
31+
android:background="#ffffff"
32+
android:text="Yes,Delete"
33+
android:layout_weight="4"
34+
android:layout_width="0dp"
35+
android:layout_height="40dp" />
36+
</LinearLayout>
4037

41-
<LinearLayout
42-
android:padding="10dp"
43-
android:background="@drawable/item_selector"
38+
<LinearLayout
39+
android:padding="10dp"
40+
android:background="@drawable/item_selector"
41+
android:layout_width="match_parent"
42+
android:layout_height="match_parent">
43+
<TextView
44+
android:id="@+id/position"
45+
android:layout_width="wrap_content"
46+
android:layout_height="wrap_content" />
47+
<TextView
48+
android:tag="Hover"
49+
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. "
4450
android:layout_width="match_parent"
45-
android:layout_height="match_parent">
46-
<TextView
47-
android:id="@+id/position"
48-
android:layout_width="wrap_content"
49-
android:layout_height="wrap_content" />
50-
<TextView
51-
android:tag="Hover"
52-
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. "
53-
android:layout_width="match_parent"
54-
android:layout_height="match_parent" />
55-
</LinearLayout>
56-
</com.daimajia.swipe.SwipeLayout>
57-
</LinearLayout>
51+
android:layout_height="match_parent" />
52+
</LinearLayout>
53+
</com.daimajia.swipe.SwipeLayout>

library/src/main/java/com/daimajia/swipe/SwipeLayout.java

-13
Original file line numberDiff line numberDiff line change
@@ -786,21 +786,8 @@ public boolean onTouchEvent(MotionEvent event) {
786786

787787
if(touching != null)
788788
touching.setPressed(true);
789-
790789
return true;
791790
case MotionEvent.ACTION_MOVE:{
792-
if(sX == -1 || sY == -1){
793-
// Trick:
794-
// When in nested mode, we need to send a constructed ACTION_DOWN MotionEvent to mDragHelper, to help
795-
// it initialize itself.
796-
event.setAction(MotionEvent.ACTION_DOWN);
797-
mDragHelper.processTouchEvent(event);
798-
parent.requestDisallowInterceptTouchEvent(true);
799-
sX = event.getRawX();
800-
sY = event.getRawY();
801-
return true;
802-
}
803-
804791
float distanceX = event.getRawX() - sX;
805792
float distanceY = event.getRawY() - sY;
806793
float angle = Math.abs(distanceY / distanceX);

0 commit comments

Comments
 (0)