Android—ListView Item 展开动画效果
最近在做一个关于ListView item的展开效果,类似于 “粮仓” App
的商店页面,点击Item,展开显示子View,类似于ExpandableListView。如图:
其实原理大家都能够猜的到,就是在Adapter里控制子View的显示与隐藏,其实这个东西看起来挺简单的,做起来,还真是费了一点功夫,其中还遇到不少知识点。其实写程序还得多思考,拿来主义固然是好,但是我们也要充分的理解每一行代码的含义,这样才能慢慢的积累更多的知识。好了不废话了,上代码。
- activity_list_view.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.jiaowenzheng.app.activity.ListViewActivity">
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
- group_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff202428"
android:orientation="vertical">
<ImageView
android:id="@+id/children_image"
android:layout_width="fill_parent"
android:layout_height="200.5dip"
android:scaleType="fitXY" />
<LinearLayout
android:id="@+id/child_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/> >
</LinearLayout>
- children_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/black">
<TextView
android:id="@+id/child_text"
android:layout_width