Android—ListView Item 展开动画效果

本文介绍如何在Android中实现ListView Item的展开动画效果,类似ExpandableListView。通过Adapter控制子View的显示隐藏,并使用自定义动画实现展开动画。详细代码包括XML布局和Java实现。由于篇幅限制,动画效果请参见提供的GitHub链接。
摘要由CSDN通过智能技术生成

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
  • 3
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值