赵雅智_名片夹(4)_Android中listview可折叠伸缩仿手风琴效果(静态)
16lz
2021-01-23
转载请标明出处: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" > <RelativeLayout android:id="@+id/rl_name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/transparent" > <TextView android:id="@+id/tv_cards_name" style="@style/cards_item_title" android:text="路人甲" /> </RelativeLayout> <RelativeLayout android:id="@+id/ll_cards" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/iv_card_list_bg" android:orientation="vertical" > <LinearLayout android:id="@+id/ll_cards_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dip" > <TextView android:id="@+id/tv_card_name" style="@style/work_detail_row_style" android:text="路人甲" android:textSize="15sp" android:textStyle="bold" /> <TextView android:id="@+id/tv_mc_otherInfo" style="@style/work_detail_row_style" android:text="财务总监" android:textColor="@color/blue" android:textSize="10dp" /> </LinearLayout> <LinearLayout android: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"> <TextView android:id="@+id/tv_mc_phoneNum" style="@style/work_detail_row_style" android:text="18933333333" /> <TextView android:id="@+id/tv_mc_mail" style="@style/work_detail_row_style" android:text="aaaaaaaaaaa@qq.com" /> <TextView android: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>
动态: 点击打开链接
更多相关文章
- android 带箭头的textview文字伸缩效果
- Android沉浸式状态栏+图片背景+标题栏渐变+背景伸缩
- android FlexboxLayout可伸缩布局
- 2011.04.14——— android 可伸缩的listview 但不是ExpandableLi
- Android实现伸缩弹力分布菜单效果
- Android UI技巧(一)——Android中伸缩自如的9patch图片切法,没有美
- 2010.12.29——— android 可伸缩的listview ExpandableList
- 关键(一): android不同机型的适配的解决方案之按比例伸缩篇