Custom slidingdrawer drawer effect (custom slidingdrawer, so that he can only drag and drop and cannot click)

Source: Internet
Author: User

 

 

Package com.cn. npass; import android. content. context; import android. graphics. rect; import android. util. attributeset; import android. view. motionevent; import android. view. view; import android. widget. slidingdrawer;/*** custom slidingdrawer, so that he can only drag and drop and cannot click **/public class clickforbiddensd extends slidingdrawer {/private int mperaction = motionevent. action_up; // whether the action is private Boolean mactioninhandle = false on handle; // The previous motioneventprivate motionevent mpreevent; Public clickforbiddensd (context, attributeset attrs) {super (context, attrs);}/*** first trigger to determine whether the contact is on handle and set mactioninhandle */@ overridepublic Boolean onintercepttouchevent (motionevent event) {view = This. gethandle (); rect = getrectonscreen (View); mactioninhandle = rect. contains (INT) event. getrawx (), (INT) event. getrawy (); return Super. onintercepttouchevent (event);}/*** get the coordinates of the view on the screen * @ Param view * @ return */private rect getrectonscreen (view) {rect = new rect (); int [] Location = new int [2]; view parent = view; If (view. getparent () instanceof view) {parent = (View) view. getparent ();} parent. getlocationonscreen (location); view. gethitrect (rect); rect. offset (location [0], location [1]); Return rect;}/*** determine whether it is a click * If yes, mask * if it is a drag, it will show * The logic is annoying, to be optimized, or even discard slidingdrawer using another */@ overridepublic Boolean ontouchevent (motionevent event) {int action = event. getaction (); If (mactioninhandle = false) {mperaction = action; return false;} If (Action = motionevent. action_up & mperaction = motionevent. action_down) {mperaction = action; return true;} If (Action = motionevent. action_move & mperaction = motionevent. action_down) {mperaction = action; super. ontouchevent (mpreevent); super. ontouchevent (event); Return true;} mperaction = action; If (Action = motionevent. action_down) {mpreevent = event; return true;} return Super. ontouchevent (event );}}

 

 

 

 

 

<?xml version="1.0" encoding="utf-8"?><merge xmlns:android="http://schemas.android.com/apk/res/android" >    <com.cn.npass.ClickForbiddenSD        android:id="@+id/sliding_drawer"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:layout_alignParentRight="true"        android:content="@+id/tag_listView"        android:handle="@+id/tag_handle"        android:orientation="horizontal"        android:background="@drawable/bg" >        <ImageView            android:id="@id/tag_handle"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:background="@drawable/icon2" />        <ListView            android:id="@id/tag_listView"            android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:background="@color/white"            android:cacheColorHint="#00000000" />    </com.cn.npass.ClickForbiddenSD></merge>

 

Package com.cn. npass; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. layoutinflater; import android. view. view; import android. view. viewgroup; import android. widget. baseadapter; import android. widget. listview; import android. widget. textview; public class mainactivity extends activity implements view. onclicklistener {private listview mlistview; @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. taglist); setupviews ();} private void setupviews () {mlistview = (listview) findviewbyid (R. id. tag_listview); mlistview. setadapter (New listviewadapter ();} private class listviewadapter extends baseadapter {// here 50 rows are returned. The number of rows in listview depends on the getcount () method public int getcount () {return 50;} public object getitem (INT arg0) {return NULL;} public long getitemid (INT arg0) {return 0;} public view getview (INT position, view V, viewgroup parent) {final layoutinflater Inflater = layoutinflater. from (getapplicationcontext (); If (V = NULL) {v = Inflater. inflate (R. layout. listview_item, null);} textview mbookname = (textview) v. findviewbyid (R. id. bookname); textview mbookauthor = (textview) v. findviewbyid (R. id. author); mbookname. settext ("android tutorial" + position); mbookauthor. settext ("SS" + position); Return v ;}@ overridepublic void onclick (view v) {// todo auto-generated method stub }}

 

 

 

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="#ffffff"    android:orientation="vertical" >    <LinearLayout        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="vertical"        android:padding="6px" >        <TextView            android:id="@+id/bookname"            android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:textColor="#000000"            android:textSize="20px" />        <TextView            android:id="@+id/author"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:textColor="#000000"            android:textSize="16px" />    </LinearLayout></LinearLayout>

 

Code: http://download.csdn.net/detail/niejing654092427/4568014

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.