編輯:關於Android編程
昨天群裡有討論時間軸的項目,沒有接觸過,以為很吊,研究之後才知道表面都是忽悠人的,使用listview就能實現了,也沒有什麼新鮮的東西
廢話少說,直接上圖
vcjLtqnWxjwvcD4KPHA+w7vKssO0usPLtbXELNaxvdPJz7T6wuuwySHP4NDFxOPE3L+0tq48L3A+CjxwPjEuyrG85NbhaXRlbbXEsry+1s7EvP48L3A+CjxwPjxwcmUgY2xhc3M9"brush:java;">
package com.sdufe.thea.guo.model; public class TimeLineModel { private int imageview; private String text; public int getImageview() { return imageview; } public void setImageview(int imageview) { this.imageview = imageview; } public String getText() { return text; } public void setText(String text) { this.text = text; } public TimeLineModel(int imageview, String text) { super(); this.imageview = imageview; this.text = text; } }3時間軸的適配器
package com.sdufe.thea.guo.adapter; import java.util.List; import com.sdufe.thea.guo.R; import com.sdufe.thea.guo.model.TimeLineModel; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; public class TimeLineAdapter extends BaseAdapter { Context context; Listlist; public TimeLineAdapter(Context context, List list) { super(); this.context = context; this.list = list; } @Override public int getCount() { if (list!=null) { return list.size(); } return 0; } @Override public Object getItem(int position) { if (list!=null) { return list.get(position); } return null; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHold hold; if (convertView==null) { hold=new ViewHold(); convertView=LayoutInflater.from(context).inflate(R.layout.timeline_item, null); convertView.setTag(hold); }else { hold=(ViewHold) convertView.getTag(); } hold.imageView=(ImageView) convertView.findViewById(R.id.left_imageview); hold.show=(TextView) convertView.findViewById(R.id.right_textview); hold.imageView.setImageResource(list.get(position).getImageview()); hold.show.setText(list.get(position).getText()); return convertView; } static class ViewHold{ public TextView show; public ImageView imageView; } }
package com.sdufe.thea.guo; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.Window; import android.widget.ListView; import com.sdufe.thea.guo.adapter.TimeLineAdapter; import com.sdufe.thea.guo.model.TimeLineModel; public class MainActivity extends Activity { private ListView listView; private Listlist; private TimeLineAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); initData(); initView(); } private void initView() { listView=(ListView) findViewById(R.id.listview); adapter=new TimeLineAdapter(this, list); listView.setAdapter(adapter); } private void initData() { list=new ArrayList (); list.add(new TimeLineModel(R.drawable.medicalcheck2, "哈哈")); list.add(new TimeLineModel(R.drawable.nurse_visit2, "呵呵")); list.add(new TimeLineModel(R.drawable.nursingcareplan2, "嘿嘿")); list.add(new TimeLineModel(R.drawable.medicalcheck2, "哈哈")); list.add(new TimeLineModel(R.drawable.nurse_visit2, "啦啦")); list.add(new TimeLineModel(R.drawable.nursingcareplan2, "咳咳")); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
代碼下載地址:http://download.csdn.net/detail/elinavampire/8179393
github下載地址:https://github.com/zimoguo/TimeLineDemo
NFC簡介 NFC是Near Field Communication縮寫,即近距離無線通訊技術。由飛利浦公司和索尼公司共同開發的NFC是一種非 接觸式識別和
用Android Studio開發前,你需要知道我寫的這個指引裡,包含了一些當你要把Eclipse項目轉到Andorid Studio前需要知道的基本信息。
開發android的同學可能會抱怨Toast設定顯示的時長無效,只能是Toast.LENGTH_LONG 或者Toast.LENGTH_SHORT 之一,為了解決這些辦法
不知不覺中,帶你一步步深入了解View系列的文章已經寫到第四篇了,回顧一下,我們一共學習了LayoutInflater的原理分析、視圖的繪制流程、視圖的狀態及重繪等知識,