对于时间轴实现,我们实现方式很多种,最直接的就是用ListView,亦或是RecyclerView都可以轻松实现。今天推荐的实现方式,不用ListView 和 RecyclerView这么强大的控件,是直接继承LinearLayout。

作者:

weipeilong123

项目地址:

https://github.com/weipeilong123/OrderStateLine

效果:

Android时间轴实现_JAVA

使用

build.gradle中引用

 

 

compile 'com.github.weipeilong123:OrderStateLine:1.0.0'

 

 

XML布局

 

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

   xmlns:app="http://schemas.android.com/apk/res-auto"

   android:layout_width="match_parent"

   android:layout_height="match_parent"

   android:background="#ffffff"

   android:orientation="vertical"

   android:scrollbars="none">

   <com.wpl.underline.UnderLineLayout

       android:id="@+id/underLineLayout"

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:orientation="vertical"

       app:line_dynamic_dimen="8dp"

       app:line_margin_side="25dp" />

</ScrollView>

 

java

 

 

 

private void addItem(String title, String content, String time, boolean isDisplayContent, int currentState) {

       View v = LayoutInflater.from(this).inflate(R.layout.view_order_state_row, underLineLayout, false);

       TextView titleTv = (TextView) v.findViewById(R.id.orderState_title);

       TextView contentTv = (TextView) v.findViewById(R.id.orderState_content);

       TextView timeTv = (TextView) v.findViewById(R.id.orderState_time);

       RelativeLayout otherRl = (RelativeLayout) v.findViewById(R.id.orderState_other);

       titleTv.setText(title);

       timeTv.setText(time);

       contentTv.setVisibility(isDisplayContent ? View.VISIBLE : View.GONE);

       if (isDisplayContent) {

           contentTv.setText(content);

           titleTv.setTextAppearance(this, R.style.BoldText);

           titleTv.setTextColor(getResources().getColor(R.color.app_color));

           if (currentState >= 3 && currentState <= 5) {

               initOtherView(otherRl);

           }

       }

       underLineLayout.addView(v);

   }

   private void initOtherView(RelativeLayout container) {

       container.setVisibility(View.VISIBLE);

       ImageView iv = new ImageView(this);

       iv.setScaleType(ImageView.ScaleType.FIT_XY);

       iv.setImageResource(R.mipmap.pic_map);

       container.addView(iv);

   }

https://mp.weixin.qq.com/s/_26lqthzWJ918bXorojpDA