Timeline of android project planing, android Project
The timeline is used in recently developed apps. The following effects must be achieved:
You can use listview to implement this. Then I wrote it in the simulation recently:
First, write the layout of the items in listview:
Listview_item.xml
<? 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"> <View android: id = "@ + id/view_0" android: layout_width = "1dp" android: layout_height = "25dp" android: layout_below = "@ + id/layout_1" android: layout_marginLeft = "71dp" android: background = "# A6A6A6"/> <View android: id = "@ + id/view_1" android: layout_width = "1dp" android: layout_height = "25dp" android: layout_below = "@ + id/layout_2" android: layout_marginLeft = "71dp" android: background = "# A6A6A6"/> <TextView android: id = "@ + id/show_time" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@ + id/view_1" android: layout_marginLeft = "30dp" android: text = "Test Data" android: textSize = "12dp"/> <ImageView android: id = "@ + id/image" android: layout_width = "15dp" android: layout_height = "15dp" android: layout_below = "@ + id/view_1" android: layout_marginLeft = "65dp" android: src = "@ drawable/timeline_green"/> <View android: id = "@ + id/view_2" android: layout_width = "1dp" android: layout_height = "100dp" android: layout_below = "@ + id/image" android: layout_marginLeft = "71dp" android: background = "# A6A6A6"/> <RelativeLayout android: id = "@ + id/relative" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_below = "@ + id/image" android: layout_marginTop = "-20dp" android: layout_toRightOf = "@ + id/image" android: background = "@ drawable/timeline_content" android: padding = "10dp"> <ImageView android: id = "@ + id/image_1" android: layout_width = "60dp" android: layout_height = "60dp" android: layout_alignParentLeft = "true" android: layout_centerVertical = "true" android: layout_marginLeft = "5dp" android: src = "@ drawable/bg_green_circle_smic"/> <TextView android: id = "@ + id/title" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_centerHorizontal = "true" android: layout_centerVertical = "true" android: ellipsize = "end" android: maxEms = "7" android: paddingLeft = "5dp" android: singleLine = "true" android: text = "Test Data" android: textSize = "12sp"/> </RelativeLayout>
The next step is to write the listview adapter:
TimelineAdapter. java
package com.example.timelinetext.test;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 Context context;private List<Map<String, Object>> list;private LayoutInflater inflater;public TimelineAdapter(Context context, List<Map<String, Object>> list) {super();this.context = context;this.list = list;}@Overridepublic int getCount() {return list.size();}@Overridepublic Object getItem(int position) {return position;}@Overridepublic long getItemId(int position) {return position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {ViewHolder viewHolder = null;if (convertView == null) {inflater = LayoutInflater.from(parent.getContext());convertView = inflater.inflate(R.layout.listview_item, null);viewHolder = new ViewHolder();viewHolder.title = (TextView) convertView.findViewById(R.id.title);convertView.setTag(viewHolder);} else {viewHolder = (ViewHolder) convertView.getTag();}String titleStr = list.get(position).get("title").toString();viewHolder.title.setText(titleStr);return convertView;}static class ViewHolder {public TextView year;public TextView month;public TextView title;}}
Last use:
MainActivity. java
Package com. example. timelinetext. test; 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; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_listview); 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 ("title", "this is 1st rows of test data"); list. add (map); map = new HashMap <String, Object> (); map. put ("title", "this is 2nd rows of test data"); list. add (map); map = new HashMap <String, Object> (); map. put ("title", "this is 3rd rows of test data"); list. add (map); map = new HashMap <String, Object> (); map. put ("title", "this is 4th rows of test data"); list. add (map); return list ;}}
Running Effect
Therefore, it is not complicated to simulate writing a timeline. Do not be scared by the image designed by ui. in fact, it is just a normal listview.
Source code download
How does android UI implement PopupWindow filling layout timeline?
This is a bit complicated. You can use
To analyze, as long as the phone stops on this interface, click this button again.
What is the difference between human physiology and human anatomy physiology?
Anatomy: refers to the structure and relationship of various parts of the body.
Physiology -- Talking about the functions of various parts