实现类似QQ滑动出现可操作项的功能,在网上看到有人自定义LinearLayout实现这个效果,但是灵活性有限。此demo使用开源项目SwipeLayout实现该功能。关于SwipeLayout的常用设置和属性,这里都做介绍,下面进入正题。一
实现类似QQ滑动出现可操作项的功能,在网上看到有人自定义LinearLayout实现这个效果,但是灵活性有限。此demo使用开源项目SwipeLayout实现该功能。关于SwipeLayout的常用设置和属性,这里都做介绍,下面进入正题。
一、效果图
二、代码片段
主页布局和主页的Java代码都和平时使用没有区别,代码没必要贴出来了。这里使用的ListView演示,还可以是GridView,ExpandableListView。
最关键的代码部分,ListView适配器布局:
<?xml version="1.0" encoding="utf-8"?><com.daimajia.swipe.SwipeLayout xmlns:Android="Http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/swipe" android:layout_width="match_parent" android:layout_height="match_parent" app:drag_edge="right"> <LinearLayout android:id="@+id/trash" android:layout_width="160dp" android:layout_height="match_parent" android:gravity="center" android:orientation="horizontal" android:tag="Bottom"> <TextView android:id="@+id/swipe_open" android:layout_width="1dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#f55509" android:gravity="center" android:text="打开" android:textColor="@android:color/white" android:textSize="20sp" /> <TextView android:id="@+id/swipe_delete" android:layout_width="1dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/holo_red_dark" android:gravity="center" android:text="删除" android:textColor="@android:color/white" android:textSize="20sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" android:gravity="center_vertical" android:orientation="horizontal" android:padding="5dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" android:orientation="vertical" android:paddingLeft="5dp"> <TextView android:id="@+id/tv_nickname" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="17sp" /> <TextView android:id="@+id/tv_msg" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:textSize="15sp" /> </LinearLayout> </LinearLayout></com.daimajia.swipe.SwipeLayout>
--结束END--
本文标题: Android实现QQ侧滑(删除、置顶等)功能
本文链接: https://www.lsjlt.com/news/219845.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0