教你3分钟了解Android 简易时间轴的实现方法

教你3分钟了解Android 简易时间轴的实现方法,第1张

概述一.有段时间没更了,因为一直在思索,应该写点什么,真的是无比纠结。这一回,就给大家分享一款简便好用的,小编自制的土晾时间轴。

一.有段时间没更了,因为一直在思索,应该写点什么,真的是无比纠结。这一回,就给大家分享一款简便好用的,小编自制的土晾时间轴。

附上XML预览图:


效果图 注:小黄鸭不是效果哈,是为了保护个人隐私P上去的:


1.新建一个自定义控件:

public class WorkExcVIEw extends linearLayout {private TextVIEw dataleft;private TextVIEw dataRight;private TextVIEw company;private TextVIEw job;private TextVIEw jobAsses;private TextVIEw xiTong;private TextVIEw ziTian;private linearLayout jobContentContainer;private TextVIEw jobContent;private linearLayout commentContainer;private linearLayout nianContentContainer;private TextVIEw nianContent;private linearLayout base;private linearLayout yueXingContainer;private TextVIEw yueContent;private linearLayout nianXingContainer;private TextVIEw yueMoreContent;private TextVIEw nianMoreContent;private String company_ID;public WorkExcVIEw(Context context) {  this(context,null);}public WorkExcVIEw(Context context,AttributeSet attrs) {  super(context,attrs);  init();}private voID init() {  VIEw inflate = VIEw.inflate(getContext(),R.layout.activity_four_workexcvIEw,this);  dataleft = (TextVIEw) inflate.findVIEwByID(R.ID.workexcvIEw_data_left);  dataRight= (TextVIEw) inflate.findVIEwByID(R.ID.workexcvIEw_data_right);  company = (TextVIEw) inflate.findVIEwByID(R.ID.workexcvIEw_company);  job = (TextVIEw) inflate.findVIEwByID(R.ID.workexcvIEw_job);  jobAsses = (TextVIEw) inflate.findVIEwByID(R.ID.workexcvIEw__job_asses);  xiTong = (TextVIEw) inflate.findVIEwByID(R.ID.workexcvIEw_xitong);  ziTian = (TextVIEw) inflate.findVIEwByID(R.ID.workexcvIEw_zitian);  jobContent = (TextVIEw) inflate.findVIEwByID(R.ID.workexcvIEw_jobcontent);  nianContent = (TextVIEw) inflate.findVIEwByID(R.ID.workexcvIEw_niancontent);  jobContentContainer = (linearLayout)inflate.findVIEwByID(R.ID.workexcvIEw_jobcontent_container);  commentContainer = (linearLayout)inflate.findVIEwByID(R.ID.workexcvIEw__comment_container);  nianContentContainer= (linearLayout)inflate.findVIEwByID(R.ID.workexcvIEw__niancontent_container);  base = (linearLayout)inflate.findVIEwByID(R.ID.workexcvIEw__base);  yueXingContainer = (linearLayout)inflate.findVIEwByID(R.ID.workexcvIEw_yuexing_container);  yueContent = (TextVIEw)inflate.findVIEwByID(R.ID.workexcvIEw_yuecontent);  nianXingContainer = (linearLayout)inflate.findVIEwByID(R.ID.workexcvIEw_nianxing_container);  yueMoreContent = (TextVIEw)inflate.findVIEwByID(R.ID.workexcvIEw_yuecontentmore);  nianMoreContent = (TextVIEw)inflate.findVIEwByID(R.ID.workexcvIEw_niancontentmore);}public voID initData(final FourBean.JobsBean jobsBean) {   //赋值代码}

XML文件:

    <?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:orIEntation="vertical"androID:ID="@+ID/workexcvIEw__base"androID:paddingleft="8dp"><relativeLayout  androID:layout_wIDth="match_parent"  androID:layout_height="wrap_content">  <ImageVIEw    androID:ID="@+ID/workexcvIEw_landian"    androID:layout_wIDth="15dp"    androID:layout_height="15dp"    androID:layout_centerVertical="true"    androID:src="@mipmap/landian" />  <TextVIEw    androID:ID="@+ID/workexcvIEw_data_left"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_centerVertical="true"    androID:layout_marginleft="3dp"    androID:layout_toRightOf="@+ID/workexcvIEw_landian"    androID:text="2016.03"    androID:textcolor="@color/text"    androID:textSize="15sp" />  <TextVIEw    androID:ID="@+ID/workexcvIEw__data_zhong"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_toRightOf="@ID/workexcvIEw_data_left"    androID:text=" ―― "    androID:textcolor="@color/text" />  <TextVIEw    androID:ID="@+ID/workexcvIEw_data_right"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_centerVertical="true"    androID:layout_toRightOf="@+ID/workexcvIEw__data_zhong"    androID:text="2016.03"    androID:textcolor="@color/text"    androID:textSize="15sp" />  <TextVIEw    androID:ID="@+ID/workexcvIEw_zitian"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_alignParentRight="true"    androID:background="@drawable/four_select"    androID:padding="4dp"    androID:paddingRight="6dp"    androID:text="自填"    androID:textcolor="@color/red"    androID:textSize="12sp"    androID:visibility="gone" />  <!--    <ImageVIEw        androID:ID="@+ID/workexcvIEw_xitong"        androID:layout_wIDth="40dp"        androID:layout_height="20dp"        androID:layout_alignParentRight="true"        androID:layout_centerVertical="true"        androID:paddingRight="10dp"        androID:src="@mipmap/xitong"        androID:visibility="gone" />-->  <TextVIEw    androID:ID="@+ID/workexcvIEw_xitong"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_alignParentRight="true"    androID:background="@drawable/textvIEw_shape"    androID:padding="4dp"    androID:paddingRight="6dp"    androID:text="系统"    androID:textcolor="@color/holo_blue_light"    androID:textSize="12sp"    androID:visibility="gone" />  <relativeLayout    androID:ID="@+ID/four_setting_workexc_container"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_alignParentRight="true"    androID:visibility="gone">    <TextVIEw      androID:ID="@+ID/four_setting_workexc_logo"      androID:layout_wIDth="wrap_content"      androID:layout_height="wrap_content"      androID:layout_alignParentRight="true"      androID:layout_centerVertical="true"      androID:text="编辑"      androID:textcolor="@androID:color/holo_blue_light"      androID:textSize="16sp" />    <ImageVIEw      androID:layout_wIDth="20dp"      androID:layout_height="20dp"      androID:layout_centerVertical="true"      androID:layout_toleftOf="@+ID/four_setting_workexc_logo"      androID:src="@drawable/xIErijIDianji3x" />  </relativeLayout></relativeLayout><linearLayout  androID:layout_wIDth="match_parent"  androID:layout_height="wrap_content"  androID:orIEntation="horizontal">  <relativeLayout    androID:layout_wIDth="wrap_content"    androID:layout_height="match_parent">    <TextVIEw      androID:layout_wIDth="1dp"      androID:layout_height="match_parent"      androID:layout_marginleft="7dp"      androID:background="@color/black" />  </relativeLayout>  <linearLayout    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:orIEntation="vertical">    <relativeLayout      androID:layout_wIDth="match_parent"      androID:layout_height="wrap_content"      androID:padding="8dp">      <TextVIEw        androID:ID="@+ID/workexcvIEw_company"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_centerVertical="true"        androID:text="某某公司"        androID:textcolor="@color/text"        androID:textSize="14sp" />      <TextVIEw        androID:ID="@+ID/workexcvIEw_company_zhong"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_centerVertical="true"        androID:layout_toRightOf="@ID/workexcvIEw_company"        androID:text=" / "        androID:textcolor="@color/text"        androID:textSize="14sp" />      <TextVIEw        androID:ID="@+ID/workexcvIEw_job"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_centerVertical="true"        androID:layout_toRightOf="@ID/workexcvIEw_company_zhong"        androID:text="web前段工程师"        androID:textcolor="@color/text"        androID:textSize="14sp" />    </relativeLayout>    <linearLayout      androID:ID="@+ID/workexcvIEw_jobcontent_container"      androID:layout_wIDth="match_parent"      androID:layout_height="wrap_content"      androID:layout_marginleft="5dp"      androID:orIEntation="vertical"      androID:padding="8dp">      <TextVIEw        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="工作描述:"        androID:textcolor="@color/text" />      <TextVIEw        androID:ID="@+ID/workexcvIEw_jobcontent"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margintop="3dp"        androID:text="巴拉巴拉" />    </linearLayout>    <linearLayout      androID:ID="@+ID/workexcvIEw__yuecontent_container"      androID:layout_wIDth="match_parent"      androID:layout_height="wrap_content"      androID:layout_marginleft="5dp"      androID:orIEntation="vertical"      androID:padding="8dp"      androID:visibility="visible">      <relativeLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content">        <TextVIEw          androID:ID="@+ID/workexcvIEw_yuecontent_logo"          androID:layout_wIDth="wrap_content"          androID:layout_height="wrap_content"          androID:layout_centerVertical="true"          androID:text="最新月评价:"          androID:textcolor="@color/text" />        <linearLayout          androID:layout_centerVertical="true"          androID:ID="@+ID/workexcvIEw_yuexing_container"          androID:layout_wIDth="wrap_content"          androID:layout_height="wrap_content"          androID:orIEntation="horizontal"          androID:layout_toRightOf="@+ID/workexcvIEw_yuecontent_logo"          >        </linearLayout>        <TextVIEw          androID:layout_alignParentRight="true"          androID:ID="@+ID/workexcvIEw_yuecontentmore"          androID:layout_wIDth="wrap_content"          androID:layout_height="wrap_content"          androID:layout_margintop="3dp"          androID:gravity="center"          androID:padding="2dp"          androID:layout_centerVertical="true"          androID:background="@drawable/textvIEw_shape"          androID:text="更多"          androID:textcolor="@color/blue_Title" />      </relativeLayout>      <TextVIEw        androID:ID="@+ID/workexcvIEw_yuecontent"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margintop="3dp"        androID:text="无"        androID:textcolor="@color/gray" />    </linearLayout>    <linearLayout      androID:ID="@+ID/workexcvIEw__niancontent_container"      androID:layout_wIDth="match_parent"      androID:layout_height="wrap_content"      androID:layout_marginleft="5dp"      androID:orIEntation="vertical"      androID:padding="8dp"      androID:visibility="visible">      <relativeLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content">        <TextVIEw          androID:ID="@+ID/workexcvIEw_niancontent_logo"          androID:layout_wIDth="wrap_content"          androID:layout_height="wrap_content"          androID:layout_centerVertical="true"          androID:text="最新年评价:"          androID:textcolor="@color/text" />        <linearLayout          androID:layout_centerVertical="true"          androID:ID="@+ID/workexcvIEw_nianxing_container"          androID:layout_wIDth="wrap_content"          androID:layout_height="wrap_content"          androID:orIEntation="horizontal"          androID:layout_toRightOf="@ID/workexcvIEw_niancontent_logo"          >        </linearLayout>        <TextVIEw          androID:ID="@+ID/workexcvIEw_niancontentmore"          androID:layout_wIDth="wrap_content"          androID:layout_height="wrap_content"          androID:layout_margintop="3dp"          androID:padding="2dp"          androID:layout_centerVertical="true"          androID:background="@drawable/textvIEw_shape"          androID:text="更多"          androID:layout_alignParentRight="true"          androID:textcolor="@color/blue_Title" />      </relativeLayout>      <TextVIEw        androID:ID="@+ID/workexcvIEw_niancontent"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margintop="3dp"        androID:text="无"        androID:textcolor="@color/gray" />    </linearLayout>    <linearLayout      androID:ID="@+ID/workexcvIEw__comment_container"      androID:layout_wIDth="match_parent"      androID:layout_height="wrap_content"      androID:layout_margin="5dp"      androID:orIEntation="vertical"      androID:padding="8dp"      androID:visibility="visible">      <TextVIEw        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="离职评价:"        androID:textcolor="@color/text" />      <TextVIEw        androID:ID="@+ID/workexcvIEw__job_asses"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margintop="3dp"        androID:text=""        androID:textcolor="@color/gray" />    </linearLayout>  </linearLayout> </linearLayout></linearLayout>      

2.使用方式:其实很简单,直接for循环new出来赋值就行啦,因为本身就是一个自定义控件~

  fourWorkexcContainer.removeAllVIEws();  for (int i = 0; i < jobs.size(); i++) {    FourBean.JobsBean jobsBean = jobs.get(i);    WorkExcVIEw workExcVIEw = new WorkExcVIEw(getContext());    workExcVIEw.initData(jobsBean);    fourWorkexcContainer.addVIEw(workExcVIEw);  } 

3.适合自己的才是最好的,大家可以根据自己的情况进行修改,也可以查阅更多的资料,以上只是一种实现的方式,随手分享。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。

总结

以上是内存溢出为你收集整理的教你3分钟了解Android 简易时间轴的实现方法全部内容,希望文章能够帮你解决教你3分钟了解Android 简易时间轴的实现方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1144908.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存