Android 时间轴
最近开发的app中要用到时间轴这东西,需要实现的效果如下:
想想这个东西应该可以用listview实现吧。然后最近就模拟着去写了:
首先写 listview的item的布局:
listview_item.xml
<?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" > <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" /> <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_centerHorizontal="true"
android:layout_centerVertical="true"
android:ellipsize="end"
android:maxEms=""
android:paddingLeft="5dp"
android:singleLine="true"
android:text="测试数据"
android:textSize="12sp" /> </RelativeLayout> </RelativeLayout>
接下来就是写listview的adapter了:
TimelineAdapter.java
package com.example.timelinetext.test; import java.util.List;
import java.util.Map; import android.content.Context;
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;
if (convertView == null) {
inflater = LayoutInflater.from(parent.getContext());
convertView = inflater.inflate(R.layout.listview_item, null);
viewHolder = new ViewHolder(); viewHolder.title = (TextView) convertView.findViewById(R.id.title);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
} String titleStr = list.get(position).get("title").toString(); viewHolder.title.setText(titleStr); return convertView;
} static class ViewHolder {
public TextView year;
public TextView month;
public TextView title;
}
}
运行效果如图:
所以模拟着去写一个时间轴,并不是什么复杂的事情,不要被UI设计的图片吓到,其实他就是一个普通的listview而已。
代码:这里
Android 时间轴的更多相关文章
- Android 时间轴的实现
时间轴 时间轴,顾名思义就是将发生的事件按照时间顺序罗列起来,给用户带来一种更加直观的体验.京东和淘宝的物流顺序就是一个时间轴(如图),想必大家都不陌生. 时间轴的初探 初次见到这种UI,感觉整个布局 ...
- Android时间轴效果,直接使用在你的项目中
近期开发app搞到历史查询,受腾讯qq的启示,搞一个具有时间轴效果的ui,看上去还能够,然后立即想到分享给小伙伴,,大家一起来看看,先上效果图吧 watermark/2/text/aHR0cDovL2 ...
- Android -- 时间轴(ListView)
1. 实现效果
- Android 时间轴TimeLine
代码:这里
- android 简易时间轴(实质是ListView)
ListView的应用 1.在很多时候是要用到时间轴的,有些处理的时间轴比较复杂,这里就给出一个比较简单的时间轴,其实就是ListView里面的Item的设计. 直接上代码: ListView,ite ...
- Android 类似时间轴的实现
想要实现图片中的的时间轴的效果,设定了三种颜色,但是出来的只有一个黑色,还不是设定好的,而且长度很长的话不能滚动,下面上代码: 布局文件: <LinearLayout xmlns:android ...
- Android自定义指示器时间轴
指示器时间轴在外卖.购物类的APP里会经常用到,效果大概就像下面这样,看了网上很多文章,大都是自己绘制,太麻烦,其实通过ListView就可以实现. 在Activity关联的布局文件activit ...
- Android实训案例(三)——实现时间轴效果的ListView,加入本地存储,实现恋爱日记的效果!
Android实训案例(三)--实现时间轴效果的ListView,加入本地存储,实现恋爱日记的效果! 感叹离春节将至,也同时感叹时间不等人,一年又一年,可是我依然是android道路上的小菜鸟,这篇讲 ...
- Android实现时间轴
昨天群里有讨论时间轴的项目,没有接触过,以为非常吊,研究之后才知道表面都是忽悠人的,使用listview就能实现了,也没有什么新奇的东西 废话少说,直接上图 图片和文字都能够私人订制 没什么好说的,直 ...
随机推荐
- OSGi运行环境下java反序列化问题的解决方式
在OSGi环境下采用以下方式对其它bundle的类进行反序列化时,会出现ClassNotFoundException异常. ByteArrayInputStream bi = new ByteArra ...
- 解决a different object with the same identifier value was already associated with the session错误
[转]解决a different object with the same identifier value was already associated with the session错误 这个错 ...
- eclipse 中卸载插件的方法
卸载步骤: Help -> About Eclipse -> Installation Details -> "点到你要删除的插件,如EclipseME" –&g ...
- 使用IntersectionObserver更高效的监视某个页面元素是否进入了可见窗口
比如说,你想跟踪 DOM 树里的一个元素,当它进入可见窗口时得到通知. 也许想实现即时延迟加载图片功能,或者你需要知道用户是否真的在看一个广告 banner. 你可以通过绑定 scroll 事件或者用 ...
- jquery如何删除一个元素后面的所有元素
$("div>span:first").nextAll().remove()
- 【bzoj1011】[HNOI2008]遥远的行星
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 3711 Solved ...
- context--command buffer
今天看了下 context ,因为要找怎么设置command buffer context为设备提供一些状态的设置和管理command buffer & const buffer buffe ...
- JavaScript之四种继承方式讲解
在Javascript中,所有开发者定义的类都可以作为基类,但出于安全性考虑,本地类和宿主类不能作为基类,这样可以防止公用访问编译过的浏览器级的代码,因为这些代码可以被用于恶意攻击. 选定基类后,就可 ...
- UML活动图(转载)
概述: 活动图是另一个重要的UML图来描述系统的动态方面. 活动图基本上是代表流程形成一个活动到另一个活动的流程图.活动可以被描述为一个系统的操作. 因此,绘制控制流从一个操作到另一个.此流可以是连续 ...
- c3p0 --2
c3p0号称是java界最好的数据池. c3p0的配置方式分为三种,分别是 1.setters一个个地设置各个配置项 2.类路径下提供一个c3p0.properties文件 3.类路径下提供一个c3p ...