前言:好久没有没有没有在博客上发东西了,前段时间做了很多需要自定义控件的东西,现在想自己写一个点击ListView的Item之后,然后弹出一个对列表Item进行操作的menu,刚开始我是直接在onItemClick里面实现了,但是感觉这样不方便以后的复用,因此花了1天的时间,重新写了一个,当然个人水平有限啊,写的时候逻辑也比较混乱,大家凑合看把。下面看下效果图
下面上代码
1、主界面的布局 activity_main.xml
<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.tata.main.ExpandableMenuListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
2、列表项布局 list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_gravity="center_vertical"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
3、列表项菜单布局
view_list_menu.xml