廢話不說,先看一下效果圖,如果大家感覺不錯,請參考實現代碼:




對于列表來說,如果想操作某個列表項,一般會采用長按彈出菜單的形式,默認的上下文菜單比較難看,而QQ的上下文菜單就人性化多了,整個菜單給用戶一種氣泡彈出的感覺,而且會顯示在手指按下的位置,而技術實現我之前是使用popupWindow和RecyclerView實現的,上面一個RecyclerView,下面一個小箭頭ImageView,但后來發現沒有必要,而且可定制化也不高,還是使用多個TextView更好一點。
我封裝了一下,只需要一個PopupList.Java文件。源碼放在了Git上,git地址:
https://github.com/shangmingchao/PopupList
使用方式,很簡單:
只需要調用該方法即可完成綁定:
PopupList popupList = new PopupList(); popupList.init(context, view, popupMenuItemList, OnPopupListClickListener);
例子:
lv_main = (ListView) findViewById(R.id.lv_main); mDataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, mDataList); lv_main.setAdapter(mDataAdapter); popupMenuItemList.add(getString(R.string.copy)); popupMenuItemList.add(getString(R.string.delete)); popupMenuItemList.add(getString(R.string.share)); popupMenuItemList.add(getString(R.string.more)); PopupList popupList = new PopupList(); popupList.init(this, lv_main, popupMenuItemList, new PopupList.OnPopupListClickListener() { @Override public void onPopupListClick(View contextView, int contextPosition, int position) { Toast.makeText(MainActivity.this, contextPosition + "," + position, Toast.LENGTH_LONG).show(); } }); ImageView indicator = new ImageView(this); indicator.setImageResource(R.drawable.popuplist_default_arrow); popupList.setIndicatorView(indicator); popupList.setIndicatorSize(dp2px(16), dp2px(8)); 以上所述是小編給大家介紹的Android仿QQ長按刪除彈出框功能示例,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答