這篇文章給大家介紹Android應(yīng)用中怎么實(shí)現(xiàn)一個(gè)跟蹤布局效果,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
我們提供的服務(wù)有:網(wǎng)站制作、成都做網(wǎng)站、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、嵊州ssl等。為上1000家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的嵊州網(wǎng)站制作公司
首頁Activity
public class TraceActivity extends AppCompatActivity { private ListView lvTrace; private List<Trace> traceList = new ArrayList<>(10); private TraceListAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_trace); findView(); initData(); } private void findView() { lvTrace = (ListView) findViewById(R.id.lvTrace); } private void initData() { // 模擬一些假的數(shù)據(jù) traceList.add(new Trace("2016年11月18日 上午12:04:01", "在湖北武漢洪山區(qū)光谷公司長(zhǎng)江社區(qū)便民服務(wù)站進(jìn)行簽收掃描,快件已被 已簽收 簽收")); traceList.add(new Trace("2016年11月18日 上午11:57:25", "在湖北武漢洪山區(qū)光谷公司長(zhǎng)江社區(qū)便民服務(wù)站進(jìn)行派件掃描;派送業(yè)務(wù)員:老王;聯(lián)系電話:17786550311")); traceList.add(new Trace("2016年11月17日 下午4:43:29", "在湖北武漢洪山區(qū)光谷公司進(jìn)行快件掃描,將發(fā)往:湖北武漢洪山區(qū)光谷公司長(zhǎng)江社區(qū)便民服務(wù)站")); traceList.add(new Trace("2016年11月17日 上午9:11:21", "從湖北武漢分撥中心發(fā)出,本次轉(zhuǎn)運(yùn)目的地:湖北武漢洪山區(qū)光谷公司")); traceList.add(new Trace("2016年11月17日 上午1:53:14", "在湖南長(zhǎng)沙分撥中心進(jìn)行裝車掃描,即將發(fā)往:湖北武漢分撥中心")); traceList.add(new Trace("2016年11月17日 上午1:50:18", "在分撥中心湖南長(zhǎng)沙分撥中心進(jìn)行稱重掃描")); traceList.add(new Trace("2016年11月16日 上午11:27:58", "在湖南隆回縣公司進(jìn)行到件掃描")); adapter = new TraceListAdapter(this, traceList); lvTrace.setAdapter(adapter); } }
然后適配器
public class TraceListAdapter extends BaseAdapter { private Context context; private List<Trace> traceList = new ArrayList<>(1); private static final int TYPE_TOP = 0x0000; private static final int TYPE_NORMAL= 0x0001; public TraceListAdapter(Context context, List<Trace> traceList) { this.context = context; this.traceList = traceList; } @Override public int getCount() { return traceList.size(); } @Override public Trace 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 Trace trace = getItem(position); if (convertView != null) { holder = (ViewHolder) convertView.getTag(); } else { holder = new ViewHolder(); convertView = LayoutInflater.from(context).inflate(R.layout.item_trace, parent, false); holder.tvAcceptTime = (TextView) convertView.findViewById(R.id.tvAcceptTime); holder.tvAcceptStation = (TextView) convertView.findViewById(R.id.tvAcceptStation); holder.tvTopLine = (TextView) convertView.findViewById(R.id.tvTopLine); holder.tvDot = (TextView) convertView.findViewById(R.id.tvDot); holder.tv_new = (TextView) convertView.findViewById(R.id.tv_new); convertView.setTag(holder); } if (getItemViewType(position) == TYPE_TOP) { // 第一行頭的豎線不顯示 holder.tvTopLine.setVisibility(View.INVISIBLE); holder.tv_new.setVisibility(View.VISIBLE); // 字體顏色加深 holder.tvAcceptTime.setTextColor(context.getResources().getColor(R.color.red)); holder.tvAcceptStation.setTextColor(context.getResources().getColor(R.color.red)); holder.tvDot.setBackgroundResource(R.drawable.timelline_dot_secord); } else if (getItemViewType(position) == TYPE_NORMAL) { holder.tvTopLine.setVisibility(View.VISIBLE); holder.tv_new.setVisibility(View.INVISIBLE); holder.tvAcceptTime.setTextColor(0xff999999); holder.tvAcceptStation.setTextColor(0xff999999); holder.tvDot.setBackgroundResource(R.drawable.timelline_dot_first); } holder.tvAcceptTime.setText(trace.getAcceptTime()); holder.tvAcceptStation.setText(trace.getAcceptStation()); return convertView; } @Override public int getItemViewType(int id) { if (id == 0) { return TYPE_TOP; } return TYPE_NORMAL; } static class ViewHolder { public TextView tvAcceptTime, tvAcceptStation; public TextView tvTopLine, tvDot,tv_new; } }
實(shí)體類
public class Trace { /** 時(shí)間 */ private String acceptTime; /** 描述 */ private String acceptStation; public Trace() { } public Trace(String acceptTime, String acceptStation) { this.acceptTime = acceptTime; this.acceptStation = acceptStation; } 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; } }
activity布局和item布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@android:color/white" tools:context="cc.duduhuo.timelinedemo.TraceActivity"> <ListView android:id="@+id/lvTrace" android:layout_width="match_parent" android:divider="@null" android:clickable="false" android:listSelector="@android:color/transparent" android:dividerHeight="0dp" android:layout_height="wrap_content" /> </LinearLayout>
<?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="75dp" android:layout_height="match_parent"> <TextView android:id="@+id/tvTopLine" android:layout_width="0.5dp" android:layout_height="12dp" android:layout_centerHorizontal="true" android:background="#999" /> <TextView android:id="@+id/tvDot" android:layout_width="5dp" android:layout_height="5dp" android:layout_margin="2dp" android:layout_below="@id/tvTopLine" android:layout_centerHorizontal="true" android:background="@drawable/timelline_dot_normal" /> <TextView android:layout_width="0.5dp" android:layout_height="match_parent" android:layout_below="@id/tvDot" android:layout_centerHorizontal="true" android:background="#999" /> <TextView android:id="@+id/tv_new" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="最新" android:textColor="#ffffff" android:background="#ff0000" android:textSize="12sp" android:layout_marginLeft="3dp" android:paddingLeft="3dp" android:paddingRight="3dp" android:layout_toRightOf="@id/tvDot" android:layout_below="@id/tvTopLine" /> </RelativeLayout> <RelativeLayout android:id="@+id/rlCenter" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="6dp" android:paddingRight="10dp" android:paddingLeft="10dp" android:paddingTop="6dp"> <TextView android:id="@+id/tvAcceptTime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2014/06/24 20:55:28" android:textColor="#999" android:textSize="12sp" /> <TextView android:id="@+id/tvAcceptStation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/tvAcceptTime" android:layout_marginTop="5dp" android:text="在湖南隆回縣公司進(jìn)行到件掃描" android:textColor="#999" android:textSize="12sp" /> </RelativeLayout> </LinearLayout>
關(guān)于Android應(yīng)用中怎么實(shí)現(xiàn)一個(gè)跟蹤布局效果就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
分享標(biāo)題:Android應(yīng)用中怎么實(shí)現(xiàn)一個(gè)跟蹤布局效果
本文來源:http://chinadenli.net/article38/joegsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、服務(wù)器托管、建站公司、企業(yè)網(wǎng)站制作、商城網(wǎng)站、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)