Android原生listview做的一个item的伸缩效果。*永远不要让你老大有机会改需求

package com.example.yunkanglast;

import java.io.Serializable;

/**
 * 状态类
 */
public class PurchasedVipInfo implements Serializable {

    public enum Type {
        CHECK_BOX,
        TEXT_VIEW,
        NO_CONTENT,
        NO_CONTENT_JUMP,
        TEXT_VIEW_HEAD
    }

    private String name;
    private String desc;
    private Type type;
    private boolean isChecked;
    private boolean isExpend;
    private String price;

    public PurchasedVipInfo(String name, String desc, Type type, boolean isExpend) {
        this.name = name;
        this.desc = desc;
        this.type = type;
        this.isExpend = isExpend;
    }

    public PurchasedVipInfo(String name, String desc, Type type, boolean isExpend,String price) {
        this.name = name;
        this.desc = desc;
        this.type = type;
        this.isExpend = isExpend;
        this.price = price;
    }

    public PurchasedVipInfo(String name, String desc, boolean isExpend) {
        this.name = name;
        this.desc = desc;
        this.isExpend = isExpend;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public boolean isChecked() {
        return isChecked;
    }

    public void setIsChecked(boolean isChecked) {
        this.isChecked = isChecked;
    }

    public boolean isExpend() {
        return isExpend;
    }

    public void setIsExpend(boolean isExpend) {
        this.isExpend = isExpend;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }
}
package com.example.yunkanglast;

import android.app.Activity;
import android.content.Context;

import android.os.Bundle;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class RegistrationPurchasedVipActivity extends Activity {

    private ListView purchasedVipInfolistView;
    private List<PurchasedVipInfo> purchasedVipInfolist;
    private RegistrationPurchasedVipAdapter pVipAdapter;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registration_purchased_vip);
        purchasedVipInfolistView = (ListView) findViewById(R.id.lv_register_healthvip_list);
        purchasedVipInfolistView.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                return true;
            }
        });
        initData();
    }

    private void initData() {
        purchasedVipInfolist = new ArrayList<PurchasedVipInfo>();
        for (int i = 1; i < 5; i++) {
            PurchasedVipInfo.Type type = PurchasedVipInfo.Type.TEXT_VIEW;
            if (i == 0) {
                type = PurchasedVipInfo.Type.NO_CONTENT;
            } else if (i > 0 && i < 3) {
                type = PurchasedVipInfo.Type.CHECK_BOX;
            } else if (i == 3) {
                type = PurchasedVipInfo.Type.NO_CONTENT_JUMP;
            } else if (i == 4) {
                type = PurchasedVipInfo.Type.TEXT_VIEW_HEAD;
            }
        }
        purchasedVipInfolist
                .add(new PurchasedVipInfo(
                        "预约挂号服务 ",
                        "客户可通过400热线、网站、手机客户端等多个渠道提供全国500多家医院的免费预约挂号服务。服务不限次数,部分医院限制同一就诊人每月不超过6次,以医院要求为准。 ",
                        PurchasedVipInfo.Type.TEXT_VIEW, false));
        purchasedVipInfolist
                .add(new PurchasedVipInfo(
                        "会员专享服务",
                        "客户可通过400热线、网站、手机客户端等多个渠道提供全国500多家医院的免费预约挂号服务。服务不限次数,部分医院限制同一就诊人每月不超过6次,以医院要求为准。 ",
                        PurchasedVipInfo.Type.TEXT_VIEW, false));
        purchasedVipInfolist
                .add(new PurchasedVipInfo(
                        "医生质询/导诊 ",
                        "客户可通过400热线、网站、手机客户端等多个渠道提供全国500多家医院的免费预约挂号服务。服务不限次数,部分医院限制同一就诊人每月不超过6次,以医院要求为准。 ",
                        PurchasedVipInfo.Type.TEXT_VIEW, false));
        purchasedVipInfolist
                .add(new PurchasedVipInfo(
                        "放号提醒 ",
                        "客户可通过400热线、网站、手机客户端等多个渠道提供全国500多家医院的免费预约挂号服务。服务不限次数,部分医院限制同一就诊人每月不超过6次,以医院要求为准。 ",
                        PurchasedVipInfo.Type.TEXT_VIEW, false));
        pVipAdapter = new RegistrationPurchasedVipAdapter(RegistrationPurchasedVipActivity.this,
                purchasedVipInfolist);
        purchasedVipInfolistView.setAdapter(pVipAdapter);

    }
}
package com.example.yunkanglast;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class RegistrationPurchasedVipAdapter extends BaseAdapter {

    private Context context;
    private List<PurchasedVipInfo> purchasedVipInfolist;
    private LayoutInflater inflater;

    public RegistrationPurchasedVipAdapter(Context context,
            List<PurchasedVipInfo> purchasedVipInfolist) {
        this.context = context;
        this.purchasedVipInfolist = purchasedVipInfolist;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return purchasedVipInfolist.size();
    }

    @Override
    public Object getItem(int position) {
        return purchasedVipInfolist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        final PurchasedVipInfo node = purchasedVipInfolist.get(position);
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.registration_purchased_vip_listview, null);
            holder.mTvDesc = (TextView) convertView
                    .findViewById(R.id.tv_register_healthvip_lists);
            holder.mIvIcon = (ImageView) convertView
                    .findViewById(R.id.iv_register_healthvip_icon);
            holder.mTvName = (TextView) convertView
                    .findViewById(R.id.tv_register_healthvip_listhead);
            holder.mHead = convertView
                    .findViewById(R.id.linear_register_healthvip_list);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (node != null) {
            PurchasedVipInfo.Type type = node.getType();
            if (type == PurchasedVipInfo.Type.NO_CONTENT) {
                holder.mHead.setVisibility(View.GONE);
                holder.mTvDesc.setVisibility(View.GONE);
            } else if (type == PurchasedVipInfo.Type.TEXT_VIEW) {

                holder.mTvName.setText(node.getName());
                holder.mTvDesc.setText(node.getDesc());

                holder.mHead.setVisibility(View.VISIBLE);
                holder.mIvIcon.setBackgroundColor(node.isExpend() ? Color.GREEN
                        : Color.RED);
                holder.mTvDesc.setVisibility(node.isExpend() ? View.VISIBLE
                        : View.GONE);
                holder.mHead.setOnClickListener(new OnpVipClickListener(holder,
                        position));

            } else if (type == PurchasedVipInfo.Type.CHECK_BOX) {

                holder.mTvName.setText(node.getName());
                holder.mTvDesc.setText(node.getDesc());

                holder.mHead.setVisibility(View.GONE);
                holder.mIvIcon.setBackgroundColor(node.isExpend() ? Color.GREEN
                        : Color.RED);
                holder.mTvDesc.setVisibility(node.isExpend() ? View.VISIBLE
                        : View.GONE);

            } else if (type == PurchasedVipInfo.Type.NO_CONTENT_JUMP) {
                holder.mTvName.setText(node.getName());
                holder.mTvDesc.setText(node.getDesc());

                holder.mHead.setVisibility(View.VISIBLE);
                holder.mIvIcon.setBackgroundColor(node.isExpend() ? Color.GREEN
                        : Color.RED);
                holder.mTvDesc.setVisibility(node.isExpend() ? View.VISIBLE
                        : View.GONE);
                holder.mHead.setOnClickListener(new OnpVipClickListener(holder,
                        position));
            } else if (type == PurchasedVipInfo.Type.TEXT_VIEW_HEAD) {
                holder.mHead.setVisibility(View.GONE);
            }
        }
        return convertView;
    }

    public class ViewHolder {
        View mHead; // listview item部分的布局
        TextView mTvName; // item 文字
        TextView mTvDesc; // item 被隐藏的文字
        ImageView mIvIcon; // item上面的指向图标
    }

    public class OnpVipClickListener implements View.OnClickListener {

        private ViewHolder holder;
        private int position;

        public OnpVipClickListener(ViewHolder holder, int position) {
            this.holder = holder;
            this.position = position;
        }

        @Override
        public void onClick(View v) {
            PurchasedVipInfo node = purchasedVipInfolist.get(position);
            if (node.isExpend()) {
                holder.mTvDesc.setVisibility(View.GONE);
                holder.mIvIcon.setImageResource(R.drawable.registration_icon_toright);
            } else {
                holder.mTvDesc.setVisibility(View.VISIBLE);
                holder.mIvIcon.setImageResource(R.drawable.registration_icon_totop);
            }
            node.setIsExpend(!node.isExpend());
        }
    }
}

xml

<!--activity_registration_purchased_vip.xml-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ececec"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:paddingBottom="25dp"
            android:paddingLeft="28dp"
            android:paddingRight="20dp"
            android:paddingTop="34dp" >

            <TextView
                android:id="@+id/tv_register_healthvip_utitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="尊敬的用户  "
                android:textColor="#333333"
                android:textSize="14sp" />

            <TextView
                android:id="@+id/tv_register_healthvip_uname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/tv_register_healthvip_utitle"
                android:layout_toRightOf="@+id/tv_register_healthvip_utitle"
                android:text="Superman"
                android:textColor="#ff5000"
                android:textSize="14sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/tv_register_healthvip_utitle"
                android:layout_toRightOf="@+id/tv_register_healthvip_uname"
                android:text=":"
                android:textColor="#333333"
                android:textSize="14sp" />

            <TextView
                android:id="@+id/tv_register_healthvip_explain"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/tv_register_healthvip_utitle"
                android:layout_below="@+id/tv_register_healthvip_utitle"
                android:layout_marginTop="16dp"
                android:lineSpacingExtra="11dp"
                android:text="您已经是小白的健康月费会员,您可以享受小百健康为您提供的覆盖全国的预约挂号服务和专业医生咨询服务,小百努力为您提供高效便捷的就医体验"
                android:textColor="#333333"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/tv_register_healthvip_viptimeprompt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/tv_register_healthvip_utitle"
                android:layout_below="@+id/tv_register_healthvip_explain"
                android:layout_marginTop="10dp"
                android:text="您的会员使用时间:"
                android:textColor="#b1b1b1"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/tv_register_healthvip_viptime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/tv_register_healthvip_viptimeprompt"
                android:layout_toRightOf="@+id/tv_register_healthvip_viptimeprompt"
                android:text="20151028-20151128"
                android:textColor="#b1b1b1"
                android:textSize="12sp" />
        </RelativeLayout>

        <View
            android:layout_width="fill_parent"
            android:layout_height="10dp"
            android:background="#eeeeee" />

        <ListView
            android:id="@+id/lv_register_healthvip_list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:listSelector="#000000"
            android:scrollbars="none" />
    </LinearLayout>

</LinearLayout>
<!--registration_purchased_vip_listview.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="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linear_register_healthvip_list"
        android:layout_width="fill_parent"
        android:layout_height="47dp"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/tv_register_healthvip_listhead"
            android:layout_width="wrap_content"
            android:layout_height="47dp"
            android:layout_marginLeft="27dp"
            android:gravity="center_vertical"
            android:textColor="#333333"
            android:textSize="13sp" />

        <View
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1" />

        <ImageView
            android:id="@+id/iv_register_healthvip_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="16dp"
            android:src="@drawable/registration_icon_toright" />
    </LinearLayout>
    <!-- listview -->

    <View
        android:layout_width="fill_parent"
        android:layout_height="0.5dp"
        android:background="#ededed" />

    <TextView
        android:id="@+id/tv_register_healthvip_lists"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:lineSpacingExtra="10dp"
        android:paddingBottom="15dp"
        android:paddingLeft="28dp"
        android:paddingRight="15dp"
        android:textColor="#999999"
        android:textSize="12sp"
        android:visibility="gone" />

</LinearLayout>

Android 原生listview item伸展收缩效果的更多相关文章

  1. Android 原生listview item伸展收缩效果 (续)

    接上一个原生的listview item的伸展收缩效果. 上一个可能做的有些粗糙,效果也没有这个好,上代码. package com.example.listviewdemo; import java ...

  2. android 修改listview item view 的方法(转)

    android 修改listview item view 的方法   具体的解答办法很简单: 代码如下 : 1.获取需要更新的view int visiblePosition = mListView. ...

  3. 【转】Android 实现ListView的滑动删除效果

    http://www.cnblogs.com/weixiao870428/p/3524055.html http://download.csdn.net/download/love_javc_you/ ...

  4. android中listview的item滑动删除效果(已解决listview点击问题)

    领导看到iphone上tableview有个滑动删除的效果,要求在android上也实现,搜了下资料,实现起来比较简单,可弄到后面,居然不能点击了,把一篇文章中的代码修改了一下,捣鼓了一番,搞定,下面 ...

  5. Android中Listview点击item不变颜色以及设置listselector 无效

    Android中Listview点击item不变颜色以及设置listselector 无效 这是同一个问题,Listview中点击item是会变颜色的,因为listview设置了默认的listsele ...

  6. Android 实现ListView不可滚动效果

    希望得到的效果是ListView不能滚动,但是最大的问题在与ListView Item还必有点击事件,如果不需要点击事件那就简单了,直接设置ListView.setEnable(false); 如果还 ...

  7. Android ListView item项 显示动画

    (1)使用LayoutAnimation 所谓的布局动画,其实就是为ViewGroup添加显示动画效果,主要用过LayoutAnimationController来控制实现.LayoutAnimati ...

  8. android自定义listview实现header悬浮框效果

    之前在使用iOS时,看到过一种分组的View,每一组都有一个Header,在上下滑动的时候,会有一个悬浮的Header,这种体验觉得很不错,请看下图: 上图中标红的1,2,3,4四张图中,当向上滑动时 ...

  9. Android 实现ListView中Item被单击后背景色保持高亮

    今天为了解决一个需求,就是我有一个slidingDrawer,里面是一个ListView.然后,单击其中的Item,默认只是显示一个橙色背景后就恢复了.客户便有着个需求,需要单击这个Item的背景高亮 ...

随机推荐

  1. href=&quot;javascript:xxx(this);&quot;和onclick=&quot;javascript:xxx(this);&quot;的区别

    href="javascript:xxx(this);"和onclick="javascript:xxx(this);" 一直以为这两种写法是等同的,今天在项目 ...

  2. strrchr 一个获取扩展名的方便的php函数

    上传文件时,$_FILES里面的name是稳健的名称,要获取扩展名就用 strrchr(str,符号)来截取最后一个.后面的扩展名 然后用 trim 去掉特殊字符. 就可以得到扩展名了

  3. 【Swift 2.1】共享文件操作小结(iOS 8 +)

    前言 适用于 iOS 8 + 本地共享文件列表 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯伯: http://over140.cnblogs ...

  4. html选择图片后预览,保存并上传

    html代码:------------------添加-------------------------- accept="image/gif,image/jpeg,image/jpg,im ...

  5. BZOJ3583 : 杰杰的女性朋友

    将$I$转置,设$G=OI$,则$ans=G^0+G^1+...+G^d$. 注意到$G^d=O(IO)^{d-1}I$,而$IO$是大小为$k\times k$的矩阵,可以通过倍增在$O(k^3\l ...

  6. nginx 负载均衡策略

    nginx 负载均衡策略   1. 轮询轮询方式是nginx负载均衡的默认策略,根据每个server的权重值来轮流发送请求,例如:upstream backend {server backend1.e ...

  7. Half Wavelength Dipole Antenna

    Reference : 1. wikipedia The dipole antenna is the simplest and most widely used class of antenna.It ...

  8. 2.Abstract Factory 抽象工厂(创建型模式)之简单工厂

    简单工厂 1.只有一个工厂(具体的,没有抽象) 2.只生产一种产品(抽象的产品) 3.这种产品可以有多种具体产品类型(派生) 代码实现 class Program { static void Main ...

  9. Windows消息初探(1)

    Windows消息初探(1) 最近恢复对Windows API的学习,深深感受到没有对应的中文资料的痛苦,于是上MSDN上面去将Windows消息搞了一些回来翻译出来,供自己查阅,也与大家分享,能力有 ...

  10. POJ 2109

    #include<iostream> #include<stdio.h> #include<math.h> using namespace std; int mai ...