Android仿ios微信左劃條目刪除、置頂的實現,程式碼簡潔,更容易理解使用
阿新 • • 發佈:2018-11-06
<span style="font-family:Arial, Helvetica, sans-serif;"><span style="background-color: rgb(255, 255, 255);">歡迎大家</span></span>
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">首先看一下效果圖(內容比較糙,還請大家擔待)</span>
實現刪除功能
實現置頂功能
實現的邏輯程式碼很簡單,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
mListView // create "top" item SwipeMenuItem topItem = new SwipeMenuItem ( getApplicationContext ()); // set item background topItem . setBackground ( new ColorDrawable ( Color . BLUE )); // set item width topItem . setWidth ( DensityUtils . dp2px ( MainActivity . this , 60 )); topItem . setTitle ( "置頂" ); topItem . setTitleSize ( 20 ); topItem . setTitleColor ( Color . WHITE ); // add to menu menu . addMenuItem ( topItem ); } }; mListView . setMenuCreator ( creator ); mListView . setOnMenuItemClickListener ( new SwipeMenuListView . OnMenuItemClickListener () { @Override public boolean onMenuItemClick ( int position , SwipeMenu menu , int index ) { switch ( index ) { case 0 : items . remove ( position ); listAdapter . notifyDataSetChanged (); break ; case 1 : String str = items . get ( position ); items . remove ( position ); items . add ( 0 , str ); listAdapter . notifyDataSetChanged (); Toast . makeText ( getApplicationContext (), "置頂成功" , Toast . LENGTH_SHORT ). show (); break ; } return false ; } }); |
實現起來很容易的,直接下載原始碼就可以使用:http://download.csdn.net/detail/ya977896216/9576796