Android自定义指示器时间轴

<ListView
android:id="@+id/lvTrace"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:divider="@null"
android:dividerHeight="0dp"
android:listSelector="@android:color/transparent" />
内容的布局,物流信息是一个RelativeLayout,为了不使两个列表项的文本靠得太近,在RelativeLayout中设置其paddingBottom和paddingTop属性。
时间轴的布局,时间轴的布局也是一个RelativeLayout,为了使时间轴的圆点和显示时间的文本对齐,我们需要在圆点之上再放置一条竖线,所以整体的布局就是 线 - 点 - 线。为了让线可以正好对准圆点的中心,我们让线和点都水平居中,即android:layout_centerHorizontal="true"
<?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:gravity="center"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/rlTimeline"
android:layout_width="wrap_content"
android:layout_marginLeft="15dp"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvTopLine"
android:layout_width="1.2dp"
android:layout_height="12dp"
android:layout_centerHorizontal="true"
android:background="#999" />
<TextView
android:id="@+id/tvDot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tvTopLine"
android:layout_centerHorizontal="true"
android:background="@drawable/state_get_huankuan" />
<TextView
android:layout_width="1.2dp"
android:id="@+id/tvLine"
android:layout_height="match_parent"
android:layout_below="@id/tvDot"
android:layout_centerHorizontal="true"
android:background="#999" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rlCenter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="6dp"
android:paddingRight="10dp"
android:layout_marginLeft="20dp"
android:paddingTop="12dp">
<TextView
android:id="@+id/step_tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"
android:text="10-20 22:22"
android:textColor="#cccccc"
android:textSize="12sp" />
<TextView
android:id="@+id/step_tv_des"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="15dp"
android:textStyle="bold"
android:layout_toLeftOf="@+id/step_tv_time"
android:text="fffffff" />
<TextView
android:id="@+id/step_tv_des_below"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/step_tv_des"
android:layout_marginTop="5dp"
android:text=""
android:textColor="#999999" />
</RelativeLayout>
</LinearLayout>
public class StepViewAdapter extends BaseAdapter {
private Context context;
private List<StepViewBean> traceList = new ArrayList<>();
private static final int TYPE_FINISH = 101;
private static final int TYPE_UNFINISH = 102;
private static final int TYPE_ERROR = 103;
public StepViewAdapter(Context context, List<StepViewBean> traceList) {
this.context = context;
this.traceList = traceList;
}
@Override
public int getCount() {
return traceList.size();
}
@Override
public StepViewBean getItem(int position) {
return traceList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
final StepViewBean trace = getItem(position);
if (convertView != null) {
holder = (ViewHolder) convertView.getTag();
} else {
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.stepview_adapter, parent, false);
holder.tvTopLine = (TextView) convertView.findViewById(R.id.tvTopLine);
holder.tvDot = (TextView) convertView.findViewById(R.id.tvDot);
holder.tvLine = (TextView) convertView.findViewById(R.id.tvLine);
holder.tvAcceptStation = (TextView) convertView.findViewById(R.id.step_tv_des);
holder.tvAcceptTime = (TextView) convertView.findViewById(R.id.step_tv_time);
holder.tvAcceptStationBelow = (TextView) convertView.findViewById(R.id.step_tv_des_below);
holder.rlTimeline = (RelativeLayout) convertView.findViewById(rlTimeline);
convertView.setTag(holder);
}
if (position == 0) {
holder.tvTopLine.setVisibility(View.INVISIBLE);
}
if (position == traceList.size() - 1) {
holder.tvLine.setVisibility(View.GONE);
} else {
holder.tvLine.setVisibility(View.VISIBLE);
}
switch (getItemViewType(position)) {
case TYPE_FINISH:
holder.tvAcceptStation.setTextColor(context.getResources().getColor(R.color.crt_completed));
holder.tvDot.setBackgroundResource(R.drawable.state_get_huankuan);
holder.tvLine.setBackgroundColor(context.getResources().getColor(R.color.crt_completed));
holder.tvTopLine.setBackgroundColor(context.getResources().getColor(R.color.crt_completed));
break;
case TYPE_UNFINISH:
holder.tvAcceptStation.setTextColor(context.getResources().getColor(R.color.crt_uncompleted_text));
holder.tvDot.setBackgroundResource(R.drawable.state_normal_huankuan);
holder.tvLine.setBackgroundColor(context.getResources().getColor(R.color.crt_text_hint_color));
break;
case TYPE_ERROR:
holder.tvTopLine.setVisibility(View.VISIBLE);
holder.tvAcceptStation.setTextColor(context.getResources().getColor(R.color.crt_error_text));
holder.tvDot.setBackgroundResource(R.drawable.state_lose_huankuan);
break;
}
holder.tvAcceptTime.setText(trace.getAcceptTime());
holder.tvAcceptStation.setText(trace.getAcceptStation());
if (!TextUtils.isEmpty(trace.getAcceptStation())) {
holder.tvAcceptStationBelow.setText(trace.getAcceptStationBelow());
}
return convertView;
}
@Override
public int getItemViewType(int id) {
if(id==(traceList.size()-2)){
return TYPE_ERROR;
}
if(id==(traceList.size()-1)){
return TYPE_UNFINISH;
}
return TYPE_FINISH;
}
static class ViewHolder {
public TextView tvAcceptTime, tvAcceptStation, tvLine, tvAcceptStationBelow;
public TextView tvTopLine, tvDot;
public RelativeLayout rlTimeline;
}
}
StepViewBean
public class StepViewBean {
/** 时间 */
private String acceptTime;
/** 描述 */
private String acceptStation;
/** 描述下方*/
private String acceptStationBelow;
public String getAcceptStationBelow() {
return acceptStationBelow;
}
public void setAcceptStationBelow(String acceptStationBelow) {
this.acceptStationBelow = acceptStationBelow;
}
public StepViewBean() {
}
public StepViewBean(String acceptTime, String acceptStation) {
this.acceptTime = acceptTime;
this.acceptStation = acceptStation;
}
public StepViewBean(String acceptTime, String acceptStation, String acceptStationBelow) {
this.acceptTime = acceptTime;
this.acceptStation = acceptStation;
this.acceptStationBelow = acceptStationBelow;
}
public String getAcceptTime() {
return acceptTime;
}
public void setAcceptTime(String acceptTime) {
this.acceptTime = acceptTime;
}
public String getAcceptStation() {
return acceptStation;
}
public void setAcceptStation(String acceptStation) {
this.acceptStation = acceptStation;
}
}
public class MainActivity extends AppCompatActivity {
private List<StepViewBean> traceList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lvTrace= (ListView) findViewById(R.id.lvTrace);
traceList.add(new StepViewBean("10-20 22: 22", "您的订单已打印完毕", "招商银行(9979) 小明\n支付金额 100000"));
traceList.add(new StepViewBean("10-20 22:22", "您已提交定单,等待系统确认"));
traceList.add(new StepViewBean("10-20 22:24", "您的订单已拣货完成"));
traceList.add(new StepViewBean("10-20 22:24", "扫描员已经扫描"));
traceList.add(new StepViewBean("10-20 22:24", "您的订单已拣货完成"));
traceList.add(new StepViewBean("10-20 22:24", "感谢你在京东购物,欢迎你下次光临!"));
StepViewAdapter adapter = new StepViewAdapter(this, traceList);
lvTrace.setAdapter(adapter);
}
}
Android自定义指示器时间轴的更多相关文章
- HighCharts 图表插件 自定义绑定 时间轴数据
HighCharts 图表插件 自定义绑定 时间轴数据,解决时间轴自动显示数据与实际绑定数据时间不对应问题! 可能要用到的源码片段:http://code.662p.com/list/14_1.htm ...
- Android 类似时间轴的实现
想要实现图片中的的时间轴的效果,设定了三种颜色,但是出来的只有一个黑色,还不是设定好的,而且长度很长的话不能滚动,下面上代码: 布局文件: <LinearLayout xmlns:android ...
- Android 时间轴
最近开发的app中要用到时间轴这东西,需要实现的效果如下: 想想这个东西应该可以用listview实现吧.然后最近就模拟着去写了: 首先写 listview的item的布局: listview_it ...
- android 简易时间轴(实质是ListView)
ListView的应用 1.在很多时候是要用到时间轴的,有些处理的时间轴比较复杂,这里就给出一个比较简单的时间轴,其实就是ListView里面的Item的设计. 直接上代码: ListView,ite ...
- Android实训案例(三)——实现时间轴效果的ListView,加入本地存储,实现恋爱日记的效果!
Android实训案例(三)--实现时间轴效果的ListView,加入本地存储,实现恋爱日记的效果! 感叹离春节将至,也同时感叹时间不等人,一年又一年,可是我依然是android道路上的小菜鸟,这篇讲 ...
- Android 时间轴的实现
时间轴 时间轴,顾名思义就是将发生的事件按照时间顺序罗列起来,给用户带来一种更加直观的体验.京东和淘宝的物流顺序就是一个时间轴(如图),想必大家都不陌生. 时间轴的初探 初次见到这种UI,感觉整个布局 ...
- Android实现时间轴
昨天群里有讨论时间轴的项目,没有接触过,以为非常吊,研究之后才知道表面都是忽悠人的,使用listview就能实现了,也没有什么新奇的东西 废话少说,直接上图 图片和文字都能够私人订制 没什么好说的,直 ...
- android项目解刨之时间轴
近期开发的app中要用到时间轴这东西.须要实现的效果例如以下: 想想这个东西应该能够用listview实现吧. 然后近期就模拟着去写了: 首先写 listview的item的布局: listview ...
- Android时间轴效果,直接使用在你的项目中
近期开发app搞到历史查询,受腾讯qq的启示,搞一个具有时间轴效果的ui,看上去还能够,然后立即想到分享给小伙伴,,大家一起来看看,先上效果图吧 watermark/2/text/aHR0cDovL2 ...
随机推荐
- jfinal使用jstl表达的存在的问及解决
问题 使用jstl 的el表达式 传递数据刷新页面,页面数据不显示,经过验证,数据的确传递过去,但是官方文档并没有详细描述,getModel() 不需要设get set() ,但是使用jstl el表 ...
- [译]ASP.NET Core 2.0 带初始参数的中间件
问题 如何在ASP.NET Core 2.0向中间件传入初始参数? 答案 在一个空项目中,创建一个POCO(Plain Old CLR Object)来保存中间件所需的参数: public class ...
- APP崩溃提示:This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.
崩溃输出日志 2017-08-29 14:53:47.332368+0800 HuiDaiKe[2373:1135604] This application is modifying the auto ...
- Integrates Git with Sublime 3 to pull or push to Github by using Sublime plugin Git
1. Git must be installed, Sublime plugin "Git" only connects Sublime with Git. Download UR ...
- C#中的异常处理(try-catch的使用)——使程序更加稳定
使用try-catch来对代码中容易出现异常的语句进行异常捕获. try { 可能出现异常的代码: } catch { 出现异常后需要执行的代码: } 注:1.在执行过程中,如果try中的代码没有出现 ...
- Fibonacci(...刷的前几道题没有记博客的习惯,吃了大亏)
Fibonacci Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- route命令实例练习
第1章 命令配置 虚拟服务器 网卡配置信息 虚拟网卡名称 虚拟网卡模式 服务器01 eth1 10.0.0.10/24 nat模式 服务器02 eth2 10.0.0.11/24 nat模式 eth3 ...
- 0_Simple__simpleAssert + 0_Simple__simpleAssert_nvrtc
在核函数中使用强制终止函数 assert().并且在静态代码和运行时编译两种条件下使用. ▶ 源代码:静态使用 #include <windows.h> #include <stdi ...
- DOM遍历 - 后代
jQuery children() 方法 children() 方法返回被选元素的所有直接子元素. 该方法只会向下一级对 DOM 树进行遍历. 您也可以使用可选参数来过滤对子元素的搜索. 下面的例子返 ...
- 图片格式 WebP APNG
WebP 是一种支持有损压缩和无损压缩的图片文件格式,派生自图像编码格式 VP8.根据 Google 的测试,无损压缩后的 WebP 比 PNG 文件少了 45% 的文件大小,即使这些 PNG 文件 ...