自定义子菜单的ListView

这篇博客介绍了如何在Android中实现点击ListView项后弹出操作菜单的功能。作者通过自定义控件,提高了代码的复用性,并分享了实现这一功能的代码和布局文件。
摘要由CSDN通过智能技术生成

前言:好久没有没有没有在博客上发东西了,前段时间做了很多需要自定义控件的东西,现在想自己写一个点击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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值