Today continue to learn "Hongxiang _" written in big God "ListView delete slides, imitation Tencent QQ" .
Today, I am ready to learn and sort out the logic QQListView.
1. Custom ListView
Take a look at the layout file activity_main.xml :
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
- <com.example.listviewitemslidedeletebtnshow.QQListView
- android:id="@+id/id_listview"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- </com.example.listviewitemslidedeletebtnshow.QQListView>
- </RelativeLayout>
Then, we will go to the line of sight com.example.listviewitemslidedeletebtnshow.QQListView class
- public class QQListView extends ListView
- {
- // First, define some properties
- // Then, define a constructor, with PopupWindow "DELETE" button, and obtain a width and height of PopupWindow ;
- // then override dispatchTouchEvent and onTouchEvent method;
- // Then, write some methods need to use;
- }
This is a very critical part of the operation (which I understand to realize the operation, is not very understanding whether there is a conflict in operation).
2.1 dispatchTouchEvent function
By dispatchTouchEvent determines whether there is "from the right to slide left" event, and determining where the touch point according to Item, where then obtained Item View;
2.2 onTouchEvent function
Sliding handle the event, determining the display position of the coordinate mPopupWindow Touch at the View, and displayed in the form of an animation.
3. Other
Place in this post, there are many values of learning, such as the use of the interface and so on. After I put these digestive above, further in-depth analysis of it.