接上一个原生的listview item的伸展收缩效果。
上一个可能做的有些粗糙,效果也没有这个好,上代码。
package com.example.listviewdemo; import java.io.Serializable; /** * 模拟数据包月列表item实体类 * 2015/11/10 * @author * */ public class PurchasedVipInfo implements Serializable { private static final long serialVersionUID = 1L; private String item; private String Ichild; private boolean isvisibility = false; public String getItem() { return item; } public void setItem(String item) { this.item = item; } public String getIchild() { return Ichild; } public void setIchild(String ichild) { Ichild = ichild; } public boolean isIsvisibility() { return isvisibility; } public void setIsvisibility(boolean isvisibility) { this.isvisibility = isvisibility; } }
package com.example.listviewdemo; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.widget.ListView; /** * 已购会员信息详情 * 2015/11/10 * @author * */ public class RegistrationPurchasedVipActivity extends Activity { private ListView nestListView; private List<PurchasedVipInfo> purchasedVipInfolist; private RegistrationPurchasedVipAdapter rpvList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_registration_purchased_vip); initUI(); initData(); } /** * 初始化数据 */ private void initData() { purchasedVipInfolist=new ArrayList<PurchasedVipInfo>(); PurchasedVipInfo priceBean=new PurchasedVipInfo(); priceBean.setItem("预约挂号服务"); priceBean.setIchild("客户可通过400热线、网站、手机客户端等多个渠道全国500多家医院的免费预约挂号服务。服务不限次数,部分医院限制同一就诊人每月不超过6次,以医院要求为准。"); purchasedVipInfolist.add(priceBean); PurchasedVipInfo priceBean1=new PurchasedVipInfo(); priceBean1.setItem("会员专享优惠"); priceBean1.setIchild("客户可通过400热线、网站、手机客户端等多个渠道全国500多家医院的免费预约挂号服务。服务不限次数,部分医院限制同一就诊人每月不超过6次,以医院要求为准。"); purchasedVipInfolist.add(priceBean1); PurchasedVipInfo priceBean2=new PurchasedVipInfo(); priceBean2.setItem("医生咨询/导诊"); priceBean2.setIchild("客户可通过400热线、网站、手机客户端等多个渠道全国500多家医院的免费预约挂号服务。服务不限次数,部分医院限制同一就诊人每月不超过6次,以医院要求为准。"); purchasedVipInfolist.add(priceBean2); PurchasedVipInfo priceBean3=new PurchasedVipInfo(); priceBean3.setItem("放号提醒"); priceBean3.setIchild("客户可通过400热线、网站、手机客户端等多个渠道全国500多家医院的免费预约挂号服务。服务不限次数,部分医院限制同一就诊人每月不超过6次,以医院要求为准。"); purchasedVipInfolist.add(priceBean3); rpvList=new RegistrationPurchasedVipAdapter(this, purchasedVipInfolist); nestListView.setAdapter(rpvList); } /** * 初始化控件 */ private void initUI() { nestListView=(ListView) findViewById(R.id.lv_register_healthvip_listview); } }
package com.example.listviewdemo; import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; /** * 会员特权详情adapter * 2015/11/10 * @author * */ public class RegistrationPurchasedVipAdapter extends BaseAdapter{ private LayoutInflater inflater; private Context context; private List<PurchasedVipInfo> priceBeanslist; public RegistrationPurchasedVipAdapter(Context context, List<PurchasedVipInfo> priceBeanslist) { super(); this.context = context; this.priceBeanslist = priceBeanslist; this.inflater=inflater.from(context); } @Override public int getCount() { return priceBeanslist.size(); } @Override public Object getItem(int position) { return priceBeanslist.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder viewHolder=null; if (convertView==null) { viewHolder=new ViewHolder(); convertView=inflater.inflate(R.layout.registration_purchased_vip_listview, null); viewHolder.item=(TextView) convertView.findViewById(R.id.tv_register_healthvip_lvitem); viewHolder.itemImage=(ImageView) convertView.findViewById(R.id.iv_register_healthvip_lvitem); viewHolder.Ichild=(TextView) convertView.findViewById(R.id.tv_register_healthvip_lvitemIchild); convertView.setTag(viewHolder); }else { viewHolder = (ViewHolder) convertView.getTag(); } ViewHolder vh=viewHolder; vh.item.setText(priceBeanslist.get(position).getItem()); vh.Ichild.setText(priceBeanslist.get(position).getIchild()); if (priceBeanslist.get(position).isIsvisibility()) { vh.Ichild.setVisibility(View.VISIBLE); vh.itemImage.setImageResource(R.drawable.registration_icon_totop); }else { vh.Ichild.setVisibility(View.GONE); vh.itemImage.setImageResource(R.drawable.registration_icon_toright); } vh.itemImage.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (priceBeanslist.get(position).isIsvisibility()) { priceBeanslist.get(position).setIsvisibility(false); }else { priceBeanslist.get(position).setIsvisibility(true); } notifyDataSetChanged(); //通知listview更新 } }); return convertView; } class ViewHolder { TextView item; //item上文字 ImageView itemImage;//item上指向图标 TextView Ichild;//item 伸展收缩textview } }
<!-- activity_registration_purchased_vip.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="#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_listview" android:layout_width="match_parent" android:layout_height="wrap_content" android:listSelector="#ffffff" > </ListView> </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="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <RelativeLayout android:layout_width="match_parent" android:layout_height="47dp" android:background="#ffffff" > <TextView android:id="@+id/tv_register_healthvip_lvitem" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="27dp" android:text="在线预约" android:textColor="#333333" android:textSize="13sp" /> <ImageView android:id="@+id/iv_register_healthvip_lvitem" android:layout_width="20dp" android:layout_height="20dp" android:src="@drawable/registration_icon_toright" android:layout_marginRight="15dp" android:layout_alignParentRight="true" android:layout_alignBottom="@+id/tv_register_healthvip_lvitem" /> <View android:layout_width="fill_parent" android:layout_height="0.5dp" android:background="#ececec" android:layout_alignParentBottom="true" /> </RelativeLayout> <TextView android:id="@+id/tv_register_healthvip_lvitemIchild" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="15dp" android:layout_marginTop="15dp" android:paddingLeft="27dp" android:paddingRight="15dp" android:lineSpacingExtra="10dp" android:textColor="#999999" android:textSize="12sp" android:visibility="gone" /> </LinearLayout>
效果图就不上了,一个会员特权详情的显示页面
主要是这个方法:
public View getView(final int position, View convertView, ViewGroup parent)