转载请标明出处:http://blog.csdn.net/zhaoyazhi2129/article/details/38060769

最近些一个名片夹得app。其中名片夹客户要求做成可折叠伸缩的效果,真是费了好大劲啊~~~啥都不说了看效果图吧~~

package com.cards.activity;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import android.app.ListActivity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;import com.cards.R;public class CardsListAct extends ListActivity implements OnScrollListener,OnItemClickListener {private static String LAYOUT_INFLATER_SERVICE = Context.LAYOUT_INFLATER_SERVICE;public static final String TV_CARDS_NAME = "tv_cards_name";public static final String TV_CARDS_PHONENUMINFO = "tv_cards_phoneNumInfo";public static final String TV_CARDS_ADDRESSINFO = "tv_cards_addressInfo";public static final String TV_CARDS_MAILINFO = "tv_cards_mailInfo";public static final String TV_CARDS_OTHERINFO = "tv_cards_otherInfo";public static final String TV_CARD_NAME = "tv_card_name";private LayoutInflater mInflater;private FlexListAdapter adapter;private List<Map<String, String>> contentDefileList;private boolean[] isCurrentItems;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);mInflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);init();setListAdapter(adapter);getListView().setBackgroundColor(Color.WHITE);getListView().setCacheColorHint(Color.TRANSPARENT);getListView().setDivider(getResources().getDrawable(R.color.transparent));getListView().setSelector(R.drawable.work_detail_click_bg);getListView().setOnScrollListener(this);getListView().setOnItemClickListener(this);}/*** 初始化数据*/private void init() {contentDefileList = new ArrayList<Map<String, String>>();Map<String, String> contentDefile = new HashMap<String, String>();contentDefile.put(TV_CARDS_NAME, "张三");contentDefile.put(TV_CARD_NAME, "张三");contentDefile.put(TV_CARDS_PHONENUMINFO, "13933333333");contentDefile.put(TV_CARDS_ADDRESSINFO, "保定市高开区朝阳北大街866号(保百购物广场南侧)");contentDefile.put(TV_CARDS_MAILINFO, "1111@qq.com");contentDefile.put(TV_CARDS_OTHERINFO, "部门经理");Map<String, String> contentDefile_1 = new HashMap<String, String>();contentDefile_1.put(TV_CARDS_NAME, "李四");contentDefile_1.put(TV_CARD_NAME, "李四");contentDefile_1.put(TV_CARDS_PHONENUMINFO, "13933333333");contentDefile_1.put(TV_CARDS_ADDRESSINFO, "保定市高开区朝阳北大街866号(保百购物广场南侧)");contentDefile_1.put(TV_CARDS_MAILINFO, "1111@qq.com");contentDefile_1.put(TV_CARDS_OTHERINFO, "经理");Map<String, String> contentDefile_2 = new HashMap<String, String>();contentDefile_2.put(TV_CARDS_NAME, "王五");contentDefile_2.put(TV_CARD_NAME, "王五");contentDefile_2.put(TV_CARDS_PHONENUMINFO, "13933333333");contentDefile_2.put(TV_CARDS_ADDRESSINFO, "hfdkajshfkadsjflkajsdlkf");contentDefile_2.put(TV_CARDS_MAILINFO, "1111@qq.com");contentDefile_2.put(TV_CARDS_OTHERINFO, "经理");Map<String, String> contentDefile_3 = new HashMap<String, String>();contentDefile_3.put(TV_CARDS_NAME, "vvv");contentDefile_3.put(TV_CARD_NAME, "vvv");contentDefile_3.put(TV_CARDS_PHONENUMINFO, "13933333333");contentDefile_3.put(TV_CARDS_ADDRESSINFO, "hfdkajshfkadsjflkajsdlkf");contentDefile_3.put(TV_CARDS_MAILINFO, "1111@qq.com");contentDefile_3.put(TV_CARDS_OTHERINFO, "设计师");Map<String, String> contentDefile_5 = new HashMap<String, String>();contentDefile_5.put(TV_CARDS_NAME, "bbb");Map<String, String> contentDefile_6 = new HashMap<String, String>();contentDefile_6.put(TV_CARDS_NAME, "ccc");contentDefile_6.put(TV_CARD_NAME, "ccc");Map<String, String> contentDefile_7 = new HashMap<String, String>();contentDefile_7.put(TV_CARDS_NAME, "ddd");contentDefile_7.put(TV_CARD_NAME, "ddd");Map<String, String> contentDefile_4 = new HashMap<String, String>();contentDefile_4.put(TV_CARDS_NAME, "aaa");contentDefile_4.put(TV_CARD_NAME, "aaa");contentDefileList.add(contentDefile);contentDefileList.add(contentDefile_1);contentDefileList.add(contentDefile_2);contentDefileList.add(contentDefile_3);contentDefileList.add(contentDefile_4);contentDefileList.add(contentDefile_6);contentDefileList.add(contentDefile_7);isCurrentItems = new boolean[contentDefileList.size()];for (int i = 0; i < isCurrentItems.length; i++) {isCurrentItems[i] = false;}Log.w("TAG", "AutoLoadActivity init() =========>>>>>> come in.");adapter = new FlexListAdapter();}public void onScroll(AbsListView v, int i, int j, int k) {}public void onScrollStateChanged(AbsListView v, int state) {if (state == OnScrollListener.SCROLL_STATE_IDLE) {}}@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position,long id) {if (isCurrentItems[position]) {isCurrentItems[position] = false;} else {isCurrentItems[position] = true;}// 即时刷新adapter.notifyDataSetChanged();}class FlexListAdapter extends BaseAdapter {int count = contentDefileList.size();public int getCount() {return count;}public Object getItem(int pos) {return pos;}public long getItemId(int pos) {return pos;}public View getView(int pos, View v, ViewGroup p) {FlexLinearLayout view = null;if (null == v) {view = new FlexLinearLayout(CardsListAct.this,contentDefileList.get(pos), pos, false);} else {view = (FlexLinearLayout) v;view.setWorkTitleLayout(contentDefileList.get(pos), pos,isCurrentItems[pos]);}return view;}}public class FlexLinearLayout extends LinearLayout {public static final int BULE = 0xFF3D8CB8;private LinearLayout layout;private RelativeLayout rlName;private RelativeLayout llCards;private TextView tvCardsPhoneNumInfo;private TextView tvCardsAddressInfo;private TextView tvCardsMailInfo;private TextView tvCardsOtherInfo;private TextView tvCardsName;private TextView tvCardName;/*** 创建一个带有伸缩效果的LinearLayout* * @param context* @param contextDefail*            内容详细* @param position*            该列所在列表的位置* @param isCurrentItem*            是否为伸展*/public FlexLinearLayout(Context context,final Map<String, String> contextDefail, final int position,boolean isCurrentItem) {super(context);layout = (LinearLayout) mInflater.inflate(R.layout.act_cards_list,null);rlName = (RelativeLayout) layout.findViewById(R.id.rl_name);llCards = (RelativeLayout) layout.findViewById(R.id.ll_cards);tvCardsPhoneNumInfo = (TextView) layout.findViewById(R.id.tv_cards_phoneNumInfo);tvCardsName = (TextView) layout.findViewById(R.id.tv_cards_name);tvCardName = (TextView) layout.findViewById(R.id.tv_card_name);tvCardsAddressInfo = (TextView) layout.findViewById(R.id.tv_cards_addressInfo);tvCardsMailInfo = (TextView) layout.findViewById(R.id.tv_cards_mailInfo);tvCardsOtherInfo = (TextView) layout.findViewById(R.id.tv_cards_otherInfo);this.addView(layout);setWorkTitleLayout(contextDefail, position, isCurrentItem);}/*** 设置该列的状态及样式* * @param contentDefail*            内容详细* @param position*            该列所在列表的位置* @param isCurrentItem*            是否为伸展*/public void setWorkTitleLayout(final Map<String, String> contentDefail,final int position, boolean isCurrentItem) {rlName.setBackgroundResource((position % 2 == 1) ? R.drawable.title_1: R.drawable.title_2);tvCardsName.setText(contentDefail.get(TV_CARDS_NAME));tvCardsName.setTextColor((position % 2 == 0) ? BULE : Color.WHITE);if (isCurrentItem) {Log.d("TAG", "isCurrentItem ============>>>>>>>>>  " + position);tvCardsPhoneNumInfo.setText("电话:"+ contentDefail.get(TV_CARDS_PHONENUMINFO));tvCardsMailInfo.setText("邮箱:"+ contentDefail.get(TV_CARDS_MAILINFO));tvCardsAddressInfo.setText("地址:"+ contentDefail.get(TV_CARDS_ADDRESSINFO));tvCardsOtherInfo.setText(contentDefail.get(TV_CARDS_OTHERINFO));tvCardName.setText(contentDefail.get(TV_CARD_NAME));}llCards.setVisibility(isCurrentItem ? VISIBLE : GONE);}}}

act_cards_list布局文件:

<?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:orientation="vertical" ><RelativeLayoutandroid:id="@+id/rl_name"android:layout_width="fill_parent"android:layout_height="wrap_content"android:background="@color/transparent" ><TextViewandroid:id="@+id/tv_cards_name"style="@style/cards_item_title"android:text="路人甲" /></RelativeLayout><RelativeLayoutandroid:id="@+id/ll_cards"android:layout_width="fill_parent"android:layout_height="wrap_content"android:background="@drawable/iv_card_list_bg"android:orientation="vertical" ><LinearLayoutandroid:id="@+id/ll_cards_name"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="20dip" ><TextViewandroid:id="@+id/tv_card_name"style="@style/work_detail_row_style"android:text="路人甲"android:textSize="15sp"android:textStyle="bold" /><TextViewandroid:id="@+id/tv_mc_otherInfo"style="@style/work_detail_row_style"android:text="财务总监"android:textColor="@color/blue"android:textSize="10dp" /></LinearLayout><LinearLayoutandroid:id="@+id/ll_cards_info"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/ll_cards_name"android:orientation="vertical" android:layout_marginTop="20dp"><TextViewandroid:id="@+id/tv_mc_phoneNum"style="@style/work_detail_row_style"android:text="18933333333" /><TextViewandroid:id="@+id/tv_mc_mail"style="@style/work_detail_row_style"android:text="aaaaaaaaaaa@qq.com" /><TextViewandroid:id="@+id/tv_mc_addressInfo"style="@style/work_detail_row_style"android:layout_width="171dp"android:layout_centerInParent="true"android:text="保定市高开区朝阳北大街866号(保百购物广场南侧)" /></LinearLayout></RelativeLayout></LinearLayout>

动态: 点击打开链接

赵雅智_名片夹(4)_Android中listview可折叠伸缩仿手风琴效果(静态)相关推荐

  1. 赵雅智_名片夹(5)_Android中listview可折叠伸缩仿手风琴效果(动态)

    转载请标明出处:http://blog.csdn.net/zhaoyazhi2129/article/details/38080857 之前写了一篇静态数据listview显示手风琴效果,今天写的博客 ...

  2. android 头部伸缩listview,AndroidUIAndroid中listview可折叠伸缩仿手风琴效果(静态) -电脑资料...

    最近些一个名片夹得app, ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ...

  3. 赵雅智_android多线程下载带进度条

    progressBar说明 在某些操作的进度中的可视指示器,为用户呈现操作的进度,还它有一个次要的进度条,用来显示中间进度,如在流媒体播放的缓冲区的进度. 一个进度条也可不确定其进度.在不确定模式下, ...

  4. 赵雅智:android教学大纲

    带下划线为详细内容链接地址.点击后可跳转.希望给大家尽一些微薄之力.眼下还在整理中 教学章节 教学内容 学时安排 备注 1 Android高速入门 2 Android模拟器与常见命令 3 Androi ...

  5. 赵雅智_Fragment生命周期

    官网帮助文档链接:  http://developer.android.com/guide/components/fragments.html 主要看两张图.和跑代码 一,Fragment的生命周 二 ...

  6. 赵雅智_Swift(2)_swift常量和变量

    分号 Swift 并不强制要求你在每条语句的结尾处使用分号(;) 你打算在同一行内写多条独立的语句必需要用分号 let cat = "? ?? ? "; println(cat) ...

  7. 赵雅智:android发彩信操作

    string.xml,布局文件,添加权限和 发送短信文章地址:http://blog.csdn.net/zhaoyazhi2129/article/details/8985598 SmsActivit ...

  8. 赵雅智_service电话监听2加接通电话录音

    步骤: 创建CallStateService继承Service 取得电话服务 监听电话动作 电话监听的对象 没有电话时 停止刻录 重设 刻录完成一定要释放资源 电话响铃时 从麦克风采集声音 内容输出格 ...

  9. 赵雅智:service_startService生命周期

    案例演示 布局文件 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xml ...

最新文章

  1. 转: HTTP 错误 401.1 - 未经授权:访问由于凭据无效被拒绝的另类解决方案
  2. iOS下音视频通信-基于WebRTC
  3. 使用javaservice 将jboss 注册为服务
  4. 内存参数 计算_Spark统一内存管理的实现
  5. python3.4学习笔记(八) Python第三方库安装与使用,包管理工具解惑
  6. hr妹子招聘黑话,面试的时候小心了!
  7. Spring学习笔记:尝试Lombok简化实体类代码
  8. 【Elasticsearch】Elasticsearch 通信模块的分析
  9. 对 比 学 习 小 综 述
  10. 大数据平台构建常见问题
  11. git svn clone
  12. 【软件工具】之录屏软件 Captura
  13. jlink6.80a烧写序列号(serial number)问题记录
  14. Shark为何被抛弃?
  15. re.sub 使用方法
  16. 《the Great Gatsby》Day 33
  17. 人脸扫描建模_人脸识别中的特征建模方法与流程
  18. Vue 中 keep-alive 组件与 router-view 组件的那点事
  19. 第一章 计算机网络和因特网
  20. 警告!中国90%AI初创企业将在两年内落败出局

热门文章

  1. 适合玩游戏的蓝牙耳机有哪些?低延迟蓝牙耳机推荐
  2. 0基础学MySQL数据库—从小白到大牛(20)大小写规范、sql_mode的合理设置
  3. 基于springboot+vue的水果销售系统附代码
  4. 磁盘管理之 raid 文件系统 分区
  5. 从创建服务器到搭建一台内网穿透服务器
  6. android简易计算器的实现
  7. linux添加五笔输入法,RedHat Linux 9中vim升级方法及如何安装五笔输入法
  8. CT图像重构方法详解——傅里叶逆变换法、直接反投影法、滤波反投影法
  9. 会场安排问题(活动场次而不是会场场次)
  10. Godot Engine:格斗游戏中的必杀技(大招/绝招/特殊技/Special Move )输入系统实现