[Study notes] "ListView delete slides, imitation Tencent QQ" (c)

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 :

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent" >  
  5.   
  6.     <com.example.listviewitemslidedeletebtnshow.QQListView  
  7.         android:id="@+id/id_listview"  
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="wrap_content" >  
  10.     </com.example.listviewitemslidedeletebtnshow.QQListView>  
  11.   
  12. </RelativeLayout>  
Here uses a custom ListView, that is QQListView. How to reflect the specific advantages of custom ListView need to achieve in com.example.listviewitemslidedeletebtnshow.QQListView class (here mainly in order to achieve sliding deleted).

Then, we will go to the line of sight com.example.listviewitemslidedeletebtnshow.QQListView class

  1. public class QQListView extends ListView  
  2. {
  3. // First, define some properties
  4. // Then, define a constructor, with PopupWindow "DELETE" button, and obtain a width and height of PopupWindow ;
  5. // then override dispatchTouchEvent and onTouchEvent method;
  6. // Then, write some methods need to use;
  7. }
2. dispatchTouchEvent and onTouchEvent exactly what has been done

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.



Published 78 original articles · won praise 54 · Views 300,000 +

Guess you like

Origin blog.csdn.net/chjr1000/article/details/44001113