admin管理员组

文章数量:1582689

效果:

需求:

不论什么领域,在模仿一个东西的时候,我们首先要对它进行需求提取,这样才能保证做到”惟妙惟肖”。通过对QQ侧滑功能的分析,提取出了以下需求:

  1. 每个Item都可以侧滑,根据Item类型的不同,侧滑后显示的菜单项也不同(联系人/群组的菜单有:置顶,标为已读,删除, 通知类消息展示的菜单只有置顶和删除);
  2. 侧滑的过程中,如果滑动距离超过第一个菜单的宽度,抬起手指时会显示全部的菜单,即Item会滑动到最左端;
  3. 在向右滑动关闭菜单的过程中,如果滑动距离超过最后一个菜单的宽度,抬起手指时会关闭全部菜单, 即Item会恢复至正常展示状态;
  4. 如果Item的菜单呈展开状态,则点击此Item或按下其他Item,当前的Item的菜单将会关闭;
  5. 如果没有Item的菜单呈展开状态,点击Item时将进入聊天页面;
  6. 观察Item滑动的过程,发现其是匀速滑动, 而不是快速移动;
  7. 不能同时滑动多个Item;

通过对需求的分析,首先会想到HorizontalScrollView, 当然,重写Item的RooView的onTouchListener()也可以实现,但是普通的View只有scrollTo()和scrollBy()方法, 只能快速移动而不能匀速移动,导致滑动的过程很生硬。所以我们使用HorizontalScrollView来实现我们的效果。

* 布局:*

根布局其实没什么内容,就是一个ListView,这样就不贴代码了, 下面我们主要展示一下Item的布局内容:

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView  xmlns:android="http://schemas.android/apk/res/android"
    android:id="@+id/horizontal_scrollview"
    android:layout_width="wrap_content"
    android:layout_height="70dp"
    android:fillViewport="true"
    android:scrollbars="none">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:gravity="center">
        <LinearLayout
            android:id="@+id/content_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:padding="12dp">
            <ImageView
                android:id="@+id/icon"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:src="@mipmap/ic_launcher"/>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="12dp"
                android:orientation="vertical">
                <TextView
                    android:id="@+id/name_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Freeman"
                    android:textSize="15sp"
                    android:textColor="#333333"/>
                <TextView
                    android:id="@+id/content_text"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity

本文标签: HorizontalScrollViewqq