Android-时间轴-TimeLine

(请尊重劳动成果,如需转载,注明转载出处,谢谢)

因为项目最近改动listview的数据,要做成时间轴的样式。所以自己先动手做了一个demo。

所以,给大家分享一下我在项目中学习到的一个小知识:时间轴 TimeLine

【一】

技术要点:

①我使用的是ExpandableListView 来作为主体布局,代替常用的listview。

②group布局和child布局 要注意那个线line的位置,很可能会出现两根线没对齐,或者是由于动态的文本高度,导致两根线中间断开。(在编写xml布局的时候一定要留意如何解决这些细节问题)



【二】

废话少说,上代码。(demo源码下载 请移步:http://download.csdn.net/detail/haoqqjy/8906443)

①adapter

public class AgendaListAdapter extends BaseExpandableListAdapter {

	private LayoutInflater inflater = null;
	private List<TimeLineTitleBean> beanList;

	public AgendaListAdapter(Context context, List<TimeLineTitleBean> list) {
		this.beanList = list;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getGroupCount() {
		return beanList.size();
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		if (beanList.get(groupPosition).getContentList() == null)
			return 0;
		else
			return beanList.get(groupPosition).getContentList().size();
	}

	@Override
	public TimeLineTitleBean getGroup(int groupPosition) {
		return beanList.get(groupPosition);
	}

	@Override
	public TimeLineContentBean getChild(int groupPosition, int childPosition) {
		return beanList.get(groupPosition).getContentList().get(childPosition);
	}

	@Override
	public long getGroupId(int groupPosition) {
		return groupPosition;
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		return childPosition;
	}

	@Override
	public boolean hasStableIds() {
		return false;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

		GroupViewHolder holder = new GroupViewHolder();
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.timeline_left, null);
		}
		holder.titleTime = (TextView) convertView.findViewById(R.id.time);
		holder.titleTime.setText(beanList.get(groupPosition).getTime());

		return convertView;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
		ChildViewHolder holder = null;
		TimeLineContentBean bean = (TimeLineContentBean) getChild(groupPosition, childPosition);

		if (convertView != null) {
			holder = (ChildViewHolder) convertView.getTag();
		} else {
			holder = new ChildViewHolder();
			convertView = inflater.inflate(R.layout.timeline_content, null);
			holder.detailTime = (TextView) convertView.findViewById(R.id.time);
			holder.auther = (TextView) convertView.findViewById(R.id.auther);
			holder.contactCount = (TextView) convertView.findViewById(R.id.contacts);
			holder.content = (TextView) convertView.findViewById(R.id.content);
			holder.back = (TextView) convertView.findViewById(R.id.back);
			holder.thumbs = (TextView) convertView.findViewById(R.id.good);
			holder.more = (TextView) convertView.findViewById(R.id.more);
		}
		holder.detailTime.setText(bean.getDetaiTime());
		holder.auther.setText(bean.getAutherName());
		holder.contactCount.setText("参与者" + bean.getContactCounts() + "人" &#
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值