Android Implementation timeline

Source: Internet
Author: User

Yesterday the group has discussed the timeline of the project, did not contact, thought very hanging, after the study to know that the surface is a bluff, the use of the ListView can be achieved, there is no fresh things

Say less nonsense, direct


Both pictures and text can be customized by private

There's nothing to say, just go to the code! I believe you can read it.

1. Timeline item's layout file

<?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:orientation=" vertical " > <linearlayout android:id= "@+id/left" android:layout_width= "Wrap_content" android:layout_he            ight= "wrap_content" android:orientation= "vertical" > <view android:layout_width= "1DP" android:layout_height= "25DP" android:layout_marginleft= "60DP" android:background= "#A6A6A6"/&G        T <imageview android:id= "@+id/left_imageview" android:layout_width= "Wrap_content" Androi d:layout_height= "Wrap_content" android:layout_marginleft= "50DP" android:src= "@drawable/medicalcheck2 "/> <view android:layout_width=" 1DP "android:layout_height=" 25DP "android:l ayout_marginleft= "60DP"            android:background= "#A6A6A6"/> </LinearLayout> <linearlayout Android:layout_alignlef t= "@id/left" android:layout_width= "match_parent" android:layout_height= "70DP" android:orientation= "ve             Rtical "android:gravity=" center "android:layout_marginleft=" 100DP "> <textview Android:id= "@+id/right_textview" android:layout_width= "match_parent" android:layout_height= "wrap _content "android:text=" AAA "/> </LinearLayout></RelativeLayout>
2. Model of pictures and text

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 Adapter for TIME axis

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; List<timelinemodel> List;public Timelineadapter (context context, list<timelinemodel> list) {super (); This.context = Context;this.list = list;} @Overridepublic int GetCount () {if (list!=null) {return list.size ();} return 0;} @Overridepublic Object getItem (int position) {if (list!=null) {return list.get (position);} return null;} @Overridepublic long Getitemid (int position) {return position;} @Overridepublic view GetView (int position, view Convertview, ViewGroup parent) {Viewhold hold;if (convertview==null) {Hol D=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;}}

Layout of the files are the same as the use of the ListView, also paste the code it, convenient for you I He

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 list<timelinemodel> list;private Timelineadapter adapter; @Overrideprotected 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<timelinemodel> (); List.add (New Timelinemodel ( R.drawable.medicalcheck2, "haha")); List.add (New Timelinemodel (R.drawable.nurse_visit2, "hehe")); List.add (New TimeLInemodel (r.drawable.nursingcareplan2, "hehe"); List.add (New Timelinemodel (R.drawable.medicalcheck2, "haha")); List.add (New Timelinemodel (R.drawable.nurse_visit2, "La La")), List.add (New Timelinemodel (r.drawable.nursingcareplan2, "cough")); @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}

OK, the code is finished, do not be fooled by the appearance of many apps


Code: http://download.csdn.net/detail/elinavampire/8179393

Github:https://github.com/zimoguo/timelinedemo


Android Implementation timeline

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.