Android实现QQ侧滑(删除、置顶等)功能-创新互联

实现类似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>

当前标题:Android实现QQ侧滑(删除、置顶等)功能-创新互联
分享地址:https://www.cdcxhl.com/article40/dpgpeo.html

成都网站建设公司_创新互联,为您提供云服务器静态网站定制网站建站公司品牌网站建设外贸建站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

绵阳服务器托管