Android时间轴效果,直接使用在你的项目中
近期开发app搞到历史查询,受腾讯qq的启示,搞一个具有时间轴效果的ui,看上去还能够,然后立即想到分享给小伙伴,,大家一起来看看,先上效果图吧
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
接下来就是代码了,axtivity的布局代码。非常easy。就是一个listview
<?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="match_parent"
android:orientation="vertical" > <ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/> </LinearLayout>
以下就是activity.java这个了
package com.agbc.activity; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.Map; import com.agbc.adapter.TimelineAdapter;
import com.agbc.listview.XListView;
import com.example.agbc.R;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject; import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.ListView;
/**
* 历史时间轴
* @author twj
*
*/
public class HistoryTaskActivity extends FragmentActivity{
private XListView listView;
List<String> data ;
private TimelineAdapter timelineAdapter;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_timeline);
findViewById();
listView.setDividerHeight(0);
timelineAdapter=new TimelineAdapter(getDate(), this);
listView.setAdapter(timelineAdapter);
} private List<Map<String, Object>> getDate() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map = new HashMap<String, Object>();
map.put("year", "2014");
map.put("month", "03/15");
map.put("title", "这是第1行測试数据");
list.add(map); map = new HashMap<String, Object>();
map.put("year", "2014");
map.put("month", "12/1");
map.put("title", "这是第2行測试数据");
list.add(map); map = new HashMap<String, Object>();
map.put("year", "2013");
map.put("month", "11/15");
map.put("title", "这是第3行測试数据");
list.add(map); map = new HashMap<String, Object>();
map.put("year", "1998");
map.put("month", "01/1");
map.put("title", "这是第4行測试数据");
list.add(map);
return list;
} private void findViewById() {
listView=(XListView) findViewById(R.id.listview); } }
接下来就是适配器了。适配器事实上也简单
package com.example.timelinetext.test; import java.util.List;
import java.util.Map; import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView; public class TimelineAdapter extends BaseAdapter { private Context context;
private List<Map<String, Object>> list;
private LayoutInflater inflater; public TimelineAdapter(Context context, List<Map<String, Object>> list) {
super();
this.context = context;
this.list = list;
} @Override
public int getCount() { return list.size();
} @Override
public Object getItem(int position) {
return position;
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
inflater = LayoutInflater.from(parent.getContext());
convertView = inflater.inflate(R.layout.adapter_timeline, null);
viewHolder = new ViewHolder();
viewHolder.year = (TextView) convertView.findViewById(R.id.year);
viewHolder.month = (TextView) convertView.findViewById(R.id.month);
viewHolder.title = (TextView) convertView.findViewById(R.id.title); String yearStr = list.get(position).get("year").toString();
String monthStr = list.get(position).get("month").toString();
String titleStr = list.get(position).get("title").toString(); viewHolder.year.setText( yearStr);
viewHolder.month.setText(monthStr);
viewHolder.title.setText(titleStr); return convertView;
} static class ViewHolder {
public TextView year;
public TextView month;
public TextView title;
}
}
最后就是适配器布局代码了,事实上效果就是在这里提现出来的
<? xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:paddingRight="20dp" > <RelativeLayout
android:id="@+id/layout_1"
android:layout_width="60dp"
android:layout_height="25dp"
android:layout_marginLeft="43dp"
android:background="@android:color/black"
android:gravity="center" > <TextView
android:id="@+id/month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="測试数据"
android:textColor="#FFFFFF"
android:textSize="12sp" />
</RelativeLayout> <View
android:id="@+id/view_0"
android:layout_width="1dp"
android:layout_height="25dp"
android:layout_below="@+id/layout_1"
android:layout_marginLeft="71dp"
android:background="#A6A6A6" /> <RelativeLayout
android:id="@+id/layout_2"
android:layout_width="60dp"
android:layout_height="25dp"
android:layout_below="@+id/view_0"
android:layout_marginLeft="43dp"
android:background="@android:color/black"
android:gravity="center" > <TextView
android:id="@+id/year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="測试数据"
android:textColor="#FFFFFF"
android:textSize="12sp" />
</RelativeLayout> <View
android:id="@+id/view_1"
android:layout_width="1dp"
android:layout_height="25dp"
android:layout_below="@+id/layout_2"
android:layout_marginLeft="71dp"
android:background="#A6A6A6" /> <TextView
android:id="@+id/show_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/view_1"
android:layout_marginLeft="30dp"
android:text="測试数据"
android:textSize="12dp" /> <ImageView
android:id="@+id/image"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_below="@+id/view_1"
android:layout_marginLeft="65dp"
android:src="@drawable/timeline_green" /> <View
android:id="@+id/view_2"
android:layout_width="1dp"
android:layout_height="100dp"
android:layout_below="@+id/image"
android:layout_marginLeft="71dp"
android:background="#A6A6A6" /> <RelativeLayout
android:id="@+id/relative"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:layout_marginTop="-20dp"
android:layout_toRightOf="@+id/image"
android:background="@drawable/timeline_content"
android:padding="10dp" > <ImageView
android:id="@+id/image_1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:src="@drawable/bg_green_circle_smic" /> <TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/image_1"
android:ellipsize="end"
android:singleLine="true"
android:maxEms="7"
android:paddingLeft="5dp"
android:text="測试数据"
android:textSize="12sp" /> <ImageView
android:id="@+id/personal_circle"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_toRightOf="@+id/title"
android:src="@drawable/ic_launcher" /> <TextView
android:id="@+id/text_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/image_1"
android:paddingLeft="5dp"
android:paddingTop="20dp"
android:text="測试数据"
android:textSize="12sp" /> <TextView
android:id="@+id/text_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/text_2"
android:ellipsize="end"
android:singleLine="true"
android:paddingTop="20dp"
android:text="測试数据"
android:textSize="12sp" /> <TextView
android:id="@+id/text_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/image_1"
android:paddingLeft="5dp"
android:paddingTop="40dp"
android:text="測试数据"
android:textSize="12sp" /> <TextView
android:id="@+id/text_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/text_4"
android:ellipsize="end"
android:singleLine="true"
android:paddingTop="40dp"
android:text="測试数据"
android:textSize="12sp" /> <TextView
android:id="@+id/text_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/image_1"
android:paddingLeft="5dp"
android:paddingTop="60dp"
android:text="測试数据"
android:textSize="12sp" /> <TextView
android:id="@+id/text_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/text_3"
android:layout_alignTop="@+id/title"
android:layout_toRightOf="@+id/text_6"
android:ellipsize="end"
android:singleLine="true"
android:paddingTop="60dp"
android:text="測试数据"
android:textSize="12sp" />
</RelativeLayout> </RelativeLayout>
好吧!时间轴事实上原理非常easy的。就是几个控件。调调位置而已,只是在实际开发中可能要对时间轴上面的控件进行操作,这就是关于事件分发的机制了,哎,事实上都是写烂的代码了。好了。这个天我要去研究tcp/ip通信了。
Android时间轴效果,直接使用在你的项目中的更多相关文章
- Android实训案例(三)——实现时间轴效果的ListView,加入本地存储,实现恋爱日记的效果!
Android实训案例(三)--实现时间轴效果的ListView,加入本地存储,实现恋爱日记的效果! 感叹离春节将至,也同时感叹时间不等人,一年又一年,可是我依然是android道路上的小菜鸟,这篇讲 ...
- 使用ExpandableListView时间轴效果达到
不废话,首先在地图上,查看结果 这是用ExpandableListView来实现时间轴效果,原理比較简单,以月份为第一级,以天为第二级来实现的. package com.hj.main; import ...
- CSS3实现时间轴效果
原文:CSS3实现时间轴效果 最近打开电脑就能看到极客学院什么新用户vip免费一个月,就进去看看咯,这里就不说它的课程怎么滴了,里面实战路径图页面看到了这个效果: 有点像时间轴的赶脚,而且每一块鼠标悬 ...
- Asp.net+jquery+ajaxpro异步仿Facebook纵向时间轴效果
Asp.net+jquery+ajaxpro异步仿Facebook纵向时间轴效果 在一个项目中,用到了时间轴展示产品的开发进度,为了更好用户体验,想到了Facebook的timeline效果, 搜了一 ...
- JS时间轴效果(类似于qq空间时间轴效果)
在上一家公司写了一个时间轴效果,今天整理了下,感觉有必要写一篇博客出来 给大家分享分享 当然代码还有很多不足的地方,希望大家多指点指点下,此效果类似于QQ空间或者人人网空间时间轴效果,当时也是为了需求 ...
- js实现的时间轴效果
今天整理以前的资料发现以前写的一个时间轴效果,当时也是网上找了很久没有找到,就自己写了一个,现在发出来给有需要的人,代码写的可能有点乱. 效果图: 下面是美工做的设计图的效果(有个美工就是好): 下面 ...
- jQuery鼠标滑过横向时间轴效果
jQuery鼠标滑过横向时间轴效果---效果图: jQuery鼠标滑过横向时间轴效果---全部代码: <!DOCTYPE html> <html> <head> & ...
- Android 时间轴
最近开发的app中要用到时间轴这东西,需要实现的效果如下: 想想这个东西应该可以用listview实现吧.然后最近就模拟着去写了: 首先写 listview的item的布局: listview_it ...
- Android 时间轴的实现
时间轴 时间轴,顾名思义就是将发生的事件按照时间顺序罗列起来,给用户带来一种更加直观的体验.京东和淘宝的物流顺序就是一个时间轴(如图),想必大家都不陌生. 时间轴的初探 初次见到这种UI,感觉整个布局 ...
随机推荐
- Linux学习日记之crontab使用notify-send实现每小时通知提醒
crontab命令用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行 通过crontab -e 可以打开编辑文件添加新的命令 notif ...
- Python学习日记之练习代码
# -*- coding:utf-8 -*- number = 23 test=True while test: guess=int(raw_input('输入数字')) if guess==numb ...
- jboss之启动加载过程详解
今天看了看jboss的boot.log和server.log日志,结合自己的理解和其他的资料,现对jboss的启动和加载过程做出如下总结: boot.xml是服务器的启动过程的日志,不涉及后续的操作过 ...
- DOM节点例子
elementNode.setAttribute(name,value) 1.name: 要设置的属性名. 2.value: 要设置的属性值. elementNode.getAttribute(nam ...
- HTML 5 <aside> 标签
定义和用法 <aside> 标签定义 article 以外的内容.aside 的内容应该与 article 的内容相关. 实例 <p>Me and my family visi ...
- JavaScipt30(第四个案例)(主要知识点:数组原型链上的一些方法)
承接上文,下面是第四个案例 附上项目链接: https://github.com/wesbos/JavaScript30 const inventors = [ { first: 'Albert', ...
- [Linux]正则表达式和grep使用【转载】
[Linux]正则表达式和grep使用 2018年12月05日 23:45:54 祥知道 阅读数 78 标签: 正则表达式grepLinuxegrep 更多 个人分类: Linux 所属专栏: Li ...
- c++通过CMake实现debug开关
刚学cmake,很多东西还不是很懂,不过今天刚刚实现了通过CMake控制debug的开关,兴奋之余记录一下. 背景介绍: 最近参与到了一个大的C++项目,很多代码已经非常成熟,我来添加一些辅助功能,但 ...
- [Python3网络爬虫开发实战] 1.1-Python3的安装
既然要用Python 3开发爬虫,那么第一步一定是安装Python 3.这里会介绍Windows.Linux和Mac三大平台下的安装过程. 1. 相关链接 官方网站:http://python.org ...
- 一:安装centos 7最小编程环境 xfce桌面
1, u盘制作安装盘------------------------------------------------------安装时, table或者e进入编辑选项 如果不知道你的u盘的盘符 ...