- 右列表标题悬停
- 左右列表滑动时联动
- 添加购物车时动画效果
右列表标题悬停&左右列表滑动时联动
github开源库:StickyListHeadersListView
StickyListHeadersListView使用:http://blog.csdn.net/zuiwuyuan/article/details/49872533
gradle添加依赖
compile 'se.emilsjolander:stickylistheaders:2.7.0'
主Layout简单,基本LinearLayout实现,左边列表直接用RecyclerView实现
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.gaoyy.stickylistdemo.MainActivity"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_above="@+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<android.support.v7.widget.RecyclerView
android:id="@+id/left"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"/>
<se.emilsjolander.stickylistheaders.StickyListHeadersListView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.7"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#433d3d"
android:orientation="horizontal">
<ImageView
android:id="@+id/cart"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="10dp"
android:layout_marginLeft="10dp"
android:src="@mipmap/icon_cart"/>
</LinearLayout>
</RelativeLayout>
数据模拟,左Type右Sample,唯一需要注意的是,在初始化数据时,数据必须按照分组顺排列
public class Sample
{
//item id
private String id;
//所属组id
private String groupId;
//item title
private String title;
//item desc
private String desc;
//组 title
private String groupTitle;
//数量
private int count;
public Sample(String id, String groupId, String title, String desc, String groupTitle,int count)
{
this.id = id;
this.groupId = groupId;
this.title = title;
this.desc = desc;
this.groupTitle = groupTitle;
this.count= count;
}
//setter and getter...
}
public class Type
{
private int status;
private String type;
public Type(int status, String type)
{
this.status = status;
this.type = type;
}
//setter and getter...
}
...
private void