android实现快递跟踪进度条

时间:2021-09-03 15:17:42

本文实例为大家分享了android快递跟踪进度条展示的具体代码,供大家参考,具体内容如下

activity.class

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
 
public class MainActivity extends Activity {
 
 private ListView listView;
 List<String> data;
 private TimelineAdapter timelineAdapter;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 listView = (ListView) this.findViewById(R.id.listview);
 listView.setDividerHeight(0);
 timelineAdapter = new TimelineAdapter(this, getData());
 listView.setAdapter(timelineAdapter);
 
 }
 
 private List<Map<String, Object>> getData() {
 List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
 
 Map<String, Object> map = new HashMap<String, Object>();
 map.put("time", "2015-05-20 10:15");
 map.put("title", "深圳龙华收件");
 list.add(map);
 
 map = new HashMap<String, Object>();
 map.put("time", "2015-05-21 9:25");
 map.put("title", "离开深圳,发往上海");
 list.add(map);
 
 map = new HashMap<String, Object>();
 map.put("time", "2015-05-22 12:55");
 map.put("title", "上海浦江集散中心");
 list.add(map);
 
 map = new HashMap<String, Object>();
 map.put("time", "2015-05-25 9:30");
 map.put("title", "已收取快件");
 list.add(map);
 return list;
 }
 
}

适配器

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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 List<Map<String, Object>> list;
 private LayoutInflater inflater;
 
 public TimelineAdapter(Context context, List<Map<String, Object>> list) {
 super();
 this.inflater = LayoutInflater.from(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) {
  convertView = inflater.inflate(R.layout.listview_item, null);
  viewHolder = new ViewHolder();
  viewHolder.time = (TextView) convertView.findViewById(R.id.tv_time);
  viewHolder.title = (TextView) convertView.findViewById(R.id.title);
  convertView.setTag(viewHolder);
 } else {
  viewHolder = (ViewHolder) convertView.getTag();
 }
 viewHolder.time.setText(list.get(position).get("time").toString());
 viewHolder.title.setText(list.get(position).get("title").toString());
 
 return convertView;
 }
 
 static class ViewHolder {
 public TextView time;
 public TextView title;
 }
}

布局文件

activity_main

?
1
2
3
4
5
6
7
8
9
10
11
12
<?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>

listview_item

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?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" >
<!--android:src="@drawable/timeline_green" 圆点图片 -->
 <ImageView
 android:id="@+id/image"
 android:layout_width="15dp"
 android:layout_height="15dp"
 android:layout_marginLeft="65dp"
 android:layout_marginTop="5dp"
 android:layout_marginBottom="5dp"
 android:scaleType="fitCenter"
 android:src="@drawable/timeline_green" />
 
 <View
 android:id="@+id/view_2"
 android:layout_width="1dp"
 android:layout_height="60dp"
 android:layout_below="@+id/image"
 android:layout_marginLeft="72dp"
 android:background="#A6A6A6" />
<!--android:background="@drawable/timeline_content" 右边图片 -->
 <RelativeLayout
 android:id="@+id/relative"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginTop="2dp"
 android:layout_toRightOf="@+id/image"
 android:background="@drawable/timeline_content"
 android:padding="5dp" >
 
 <TextView
  android:id="@+id/title"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:singleLine="true"
  android:layout_marginLeft="5dp"
  android:textSize="13sp" />
 
 <TextView
  android:id="@+id/tv_time"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_below="@id/title"
  android:layout_marginLeft="5dp"
  android:textColor="#0000ff"
  android:textSize="9sp" />
 
 </RelativeLayout>
 
</RelativeLayout>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/menglele1314/article/details/45967451