—————————————————— as above ————————————————
The effect is: the left and right of the screen can be dragged up and down independently, provided that the height of the lower half of the upper part of the screen upward drag, is the overall picture drag up
Activity_main.xml
<com.atguigu.pinterestlistview.mylinearlayout xmlns:android= "Http://schemas.android.com/apk/res/android" xmlns:tools= "Http://schemas.android.com/tools" android:id= "@+id/mll" android:layout_width= "Match_parent" Android: layout_height= "Match_parent" tools:context= ". Mainactivity "> <listview android:id=" @+id/lv2 "android:layout_width=" 0DP "Android:layout_we ight= "1" android:layout_height= "Wrap_content" android:scrollbars= "None"/> <listview Android : id= "@+id/lv1" android:layout_width= "0DP" android:layout_weight= "1" android:layout_height= "Wrap_conte NT "android:scrollbars=" None "/> <listview android:id=" @+id/lv3 "android:layout_width=" 0DP " android:layout_weight= "1" android:layout_height= "Wrap_content" android:scrollbars= "None"/></co M.atguigu.pinterestlistview.mylinearlayout>
Lv_item.xml
<imageview xmlns:android= "http://schemas.android.com/apk/res/android" android:id= "@+id/iv" android: Layout_width= "Wrap_content" android:layout_height= "wrap_content" android:adjustviewbounds= "true" android:src= "@drawable/default1"/>
Mainactivity.java
Package Com.atguigu.pinterestlistview;import Android.app.activity;import Android.os.bundle;import Android.view.view;import Android.view.viewgroup;import Android.widget.baseadapter;import Android.widget.ImageView Import Android.widget.listview;public class Mainactivity extends Activity {/* * define three listview */private ListView Lv1;priv Ate listview lv2;private listview Lv3; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_main);//Get LISTVIEWLV1 = (ListView) Findviewbyid (R.ID.LV1); Lv2 = (ListView) Findviewbyid (R.ID.LV2), Lv3 = (ListView) Findviewbyid (R.id.lv3);//Set adapter try {Lv1.setadapter (new MyAdapter1 ()); Lv2.setadapter (new MyAdapter1 ()); Lv3.setadapter (new MyAdapter1 ());} catch (Exception e) {e.printstacktrace ();}} Prepare the desired picture resource private int ids[] = new int[] {r.drawable.default1, r.drawable.girl1,r.drawable.girl2, R.drawable.girl3, R.drawable.girl4};class MyAdapter1 extends Baseadapter {@Overridepublic int getcount () {RETurn 3000;} @Overridepublic Object getItem (int position) {return position;} @Overridepublic long Getitemid (int position) {return 0;} @Overridepublic view GetView (int position, view Convertview, ViewGroup parent) {ImageView IV = (ImageView) view.inflate (ge Tapplicationcontext (), r.layout.lv_item, NULL);//0<=math.random () * 5<5int resId = (int) (Math.random () * 5); Iv.setimageresource (Ids[resid]); return IV;}}
Mylinearlayout.java
Package Com.atguigu.pinterestlistview;import Android.content.context;import Android.util.attributeset;import Android.view.motionevent;import Android.view.view;import Android.widget.linearlayout;public class MyLinearLayout Extends LinearLayout {/** * First step execution constructor */public mylinearlayout (context context, AttributeSet Attrs) {Super (context, attrs); }/** * Onintercepttouchevent (); Intercept Touch Event 1. If True is returned, the current view's ontouchevent () will be triggered; * 2. If the return is false, the event will be passed to the child */@Overridepublic Boolean onintercepttouchevent (motionevent ev) {//causes the Ontouch event to execute return true;} @Overridepublic boolean ontouchevent (Motionevent event) {//screen One-third int width = getwidth ()/Getchildcount (); int height = g Etheight (); int count = Getchildcount ();//get X coordinate value float eventx = Event.getx ();//Slide left listviewif (Eventx < width) {//set with The effect interval event.setlocation (WIDTH/2, Event.gety ());//distribution event to Listviewgetchildat (0). Dispatchtouchevent (event);//Returns True, Description List processing event return true;} else if (Eventx > Width && eventx < 2 * width) {//Sliding middle listview//To the middle of the listview, click y value float eventy = event.gety ();//If the screen is above 1/2 (upper part of the screen) if (Eventy < HEIGHT/2) {event.setlocation (WIDTH/2 Event.gety ()); for (int i = 0; i < count; i++) {//Get three listview view View child = Getchildat (i); try {Child.dispatchtoucheve NT (event);} catch (Exception e) {e.printstacktrace ();}} Returns true, indicating that the list handles the event return true; else if (Eventy > Height/2) {event.setlocation (WIDTH/2, Event.gety ()); Getchildat (1). Dispatchtouchevent (event); return true;}} else if (Eventx > 2 * width) {event.setlocation (WIDTH/2, Event.gety ()); Getchildat (2). Dispatchtouchevent (event); return true;} return true;}}
Event mechanism (classic case + otaku benefits)