亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android使用Item Swipemenulistview實(shí)現(xiàn)仿QQ側(cè)滑刪除功能

 更新時(shí)間:2017年02月27日 13:54:56   投稿:mrr  
大家都用過QQ,肯定有人好奇QQ滑動(dòng)刪除Item的效果是怎樣實(shí)現(xiàn)的,其實(shí)我們使用Swipemenulistview就可以簡(jiǎn)單的實(shí)現(xiàn)。這篇文章主要介紹了Android使用ItemSwipemenulistview實(shí)現(xiàn)仿QQ側(cè)滑刪除功能,需要的朋友可以參考下

 大家都用過QQ,肯定有人好奇QQ滑動(dòng)刪除Item的效果是怎樣實(shí)現(xiàn)的,其實(shí)我們使用Swipemenulistview就可以簡(jiǎn)單的實(shí)現(xiàn)。先看看我們項(xiàng)目中的效果:

   使用的時(shí)候可以把Swipemenulistview作為一個(gè)library,也可以把Swipemenulistview的源碼拷貝到我們的項(xiàng)目中來(lái),使用步驟大致可以分為三步:1.在布局中配置;2.在Java代碼中初始化配置;3.按鈕點(diǎn)擊事件的處理

 1.在布局中配置

 xml布局文件中只需要簡(jiǎn)單使用這個(gè)自定義的ListView就行了,需要注意的是必須使用類的全名。

 <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.baoyz.swipemenulistview.SwipeMenuListView 
  android:id="@+id/listView" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" /> 
 </RelativeLayout> 

2.在java代碼中初始化菜單配置

 SwipeMenuCreator creator = new SwipeMenuCreator(){ 
 <span style="white-space:pre">  </span>@Override 
 public void create(SwipeMenu menu) { 
  //創(chuàng)建一個(gè)"打開"功能菜單 
  SwipeMenuItem openItem = new SwipeMenuItem(context); 
  // 設(shè)置菜單的背景 
  openItem.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9,0xCE))); 
  // 寬度:菜單的寬度是一定要有的,否則不會(huì)顯示 
  openItem.setWidth(180); 
  // 菜單標(biāo)題 
  openItem.setTitle("打開"); 
  // 標(biāo)題文字大小 
  openItem.setTitleSize(16); 
  // 標(biāo)題的顏色 
  openItem.setTitleColor(Color.WHITE); 
  // 添加到menu 
  menu.addMenuItem(openItem); 
  //創(chuàng)建一個(gè)"打開"功能菜單 
  SwipeMenuItem deleteItem = new SwipeMenuItem(context); 
  // 設(shè)置菜單的背景 
  deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9,0x3F, 0x25))); 
  // 寬度:菜單的寬度是一定要有的,否則不會(huì)顯示 
  deleteItem.setWidth(180); 
  // 菜單標(biāo)題 
  deleteItem.setTitle("刪除"); 
  // 標(biāo)題文字大小 
  deleteItem.setTitleSize(16); 
  // 標(biāo)題的顏色 
  deleteItem.setTitleColor(Color.WHITE); 
  // 給菜單設(shè)置一個(gè)圖標(biāo) 
  //deleteItem.setIcon(R.drawable.ic_delete); 
  // 添加到menu 
  menu.addMenuItem(deleteItem); 
 } 
 }; 
 // 不要忘記了 
 mListView.setMenuCreator(creator); 

 這里是添加了兩個(gè)菜單按鈕,一個(gè)“打開”,一個(gè)“刪除”。

 3.菜單按鈕點(diǎn)擊事件的處理

 mListView.setOnMenuItemClickListener(new OnMenuItemClickListener() { 
 @Override 
 public void onMenuItemClick(int position, SwipeMenu menu, int index) { 
  switch (index) { 
  case 0: 
  Toast.makeText(context, "打開第" + mArrayList.get(position) + "個(gè)條目", 0).show(); 
  break; 
  case 1: 
  Toast.makeText(context, "刪除第" + mArrayList.get(position) + "個(gè)條目", 0).show(); 
  mArrayList.remove(position); 
  mAdapter.notifyDataSetChanged(); 
  break; 
  } 
 } 
 }); 

 最后的效果圖如下:

以上所述是小編給大家介紹的Android使用Item Swipemenulistview實(shí)現(xiàn)仿QQ側(cè)滑刪除功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論