本来准备在ListView的每个Item的布局上设置一个隐藏的Button,当滑动的时候显示。但是因为每次只要存在一个Button,发现每个Item上的Button相互间不好控制。所以决定继承ListView然后结合PopupWindow。
首先是布局文件:
delete_btn.xml:这里只需要一个Button
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:andro 3 android:layout_width="wrap_content" 4 android:layout_height="wrap_content" 5 android:orientation="vertical" > 6 <Button 7 android: 8 android:layout_width="60dp" 9 android:singleLine="true" 10 android:layout_height="wrap_content" 11 android:text="删除" 12 android:background="@drawable/d_delete_btn" 13 android:textColor="#ffffff" 14 android:paddingLeft="15dp" 15 android:paddingRight="15dp" 16 android:layout_alignParentRight="true" 17 android:layout_centerVertical="true" 18 android:layout_marginRight="15dp" 19 /> 20 </LinearLayout>