Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android物流跟蹤

Android物流跟蹤

編輯:關於Android編程

最近在網上看到時間軸的布局效果,嘗試按照這個原理,實現物流跟蹤的效果,目前已經實現了,效果如下圖。

 


\

 

 

界面布局主要是通過listView來實現的,listView item 左右布局。左邊是豎線,狀態圖片,豎線。右邊 是 物流信息和 時間。

開始左邊線的高度很不好適配,最後請教網友,用了layout_weight屬性。

豎線本來使用的是ImageView顯示,結果線的高度變小,寬度也隨之變小,導致屏幕根本看不清左邊布局中狀態圖片上的線。

最後采用了View來繪制豎線,效果還挺理想的額。

具體的布局如下:

 

 

 

自定義的適配器:

 

public class TimeLineAdapter extends BaseAdapter {

	private Context mcontext=null;
    private List mlist=null;
	private LayoutInflater minflater;
	
	public TimeLineAdapter ( Context context, List list  ){
		this.mcontext = context;
		minflater = LayoutInflater.from(context);
		mlist = list;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if( null!=mlist){
			return mlist.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		if( null!=mlist){
			return mlist.get(position);
		 }
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint(InflateParams)
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub	
		 ViewHold viewHold;
		if(convertView == null){
			viewHold = new ViewHold();
			convertView = minflater.inflate(R.layout.timeline_item, null);
			viewHold.imageView1 = (ImageView)convertView.findViewById(R.id.mgView_logistic_tracking_status);
			viewHold.textView1 = (TextView)convertView.findViewById(R.id.tv_logistic_tracking_address);
			viewHold.textView2 = (TextView)convertView.findViewById(R.id.tv_logistic_tracking_time);
			viewHold.line1 = (View)convertView.findViewById(R.id.View_logistic_tracking_line1);
			convertView.setTag(viewHold);
		}else {
			viewHold = (ViewHold)convertView.getTag( );
		}
		if(position==0){
			viewHold.line1.setVisibility(View.INVISIBLE);
			viewHold.imageView1.setImageResource(R.drawable.logistics_state);
		}else{
			viewHold.line1.setVisibility(View.VISIBLE);
			viewHold.imageView1.setImageResource(R.drawable.logistics_state1);
		}
		viewHold.textView1.setText( mlist.get(position).getMaddress());
		viewHold.textView2.setText( mlist.get(position).getMtime());
		return convertView;
	}
	

    private final static class ViewHold{
    	
        ImageView imageView1;
        View line1;
    	TextView  textView1;
    	TextView textView2;  	
    }
}

TimeLine定義:

 

 

public class TimeLine {

	private String  maddress;
	private String  mtime;
	
	public TimeLine( String address ,String time){

		this.maddress = address;
		this.mtime = time;
	}


	public String getMaddress() {
		return maddress;
	}

	public void setMaddress(String maddress) {
		this.maddress = maddress;
	}

	public String getMtime() {
		return mtime;
	}

	public void setMtime(String mtime) {
		this.mtime = mtime;
	}
}


 

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved