欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android StepView實現(xiàn)物流進度效果

 更新時間:2018年05月16日 11:04:43   作者:danfengw  
這篇文章主要為大家詳細介紹了Android StepView實現(xiàn)物流進度效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android StepView物流進度的具體代碼,供大家參考,具體內(nèi)容如下

這里寫圖片描述

之前看了一個別人寫的物流進度的demo,自定義View用的挺好的,但是感覺太麻煩了,就自己寫了一個簡單的,思路很簡單,上面是效果圖。

思路

思路:主要是進行了動態(tài)添加,根據(jù)上面的效果展示,創(chuàng)建一個子布局,如下圖所示(代碼里面的布局圖一個ImageView一個View一個TextView),然后自定義一個MyVerticalView繼承LinearLayout(注意設(shè)置orientation),在MyVerticalView中根據(jù)數(shù)據(jù)來addview()就可以了

代碼

這里寫圖片描述 

Model

mode的具體變量是根據(jù)上面item的布局,我們需要知道當前的狀態(tài)跟具體過程描述。狀態(tài)分為下面三種情況:
STATE_PROCESSING:正在進行中(圖標如下)

這里寫圖片描述 

STATE_COMPLETED:已經(jīng)完成(圖標如下)

這里寫圖片描述 

STATE_DEFAULT:最后默認步驟(圖標如下)

這里寫圖片描述

根據(jù)上面分析需要兩個變量,currentState是為了根據(jù)狀態(tài)設(shè)置不同圖標的

private String description;//當前狀態(tài)描述
 private String currentState;//當前狀態(tài)(上面三個狀態(tài)中的一個)

完整

public class StepModel {
 public static final String STATE_PROCESSING="PROCESSING";//正在進行的狀態(tài)
 public static final String STATE_COMPLETED="COMPLETED";//已經(jīng)完成的狀態(tài)
 public static final String STATE_DEFAULT="DEFAULT";//結(jié)尾的默認狀態(tài)
 private String description;//當前狀態(tài)描述
 private String currentState;//當前狀態(tài)(上面三個狀態(tài)中的一個)
 public StepModel(String description, String currentState) {
  this.description = description;
  this.currentState = currentState;
 }
 public String getCurrentState() {
  return currentState;
 }
 public void setCurrentState(String currentState) {
  this.currentState = currentState;
 }

 public String getDescription() {
  return description;
 }
 public void setDescription(String description) {
  this.description = description;
 }
}

StepView

public class MyVerticalStepView extends LinearLayout {
 private List<StepModel> mDatas = new ArrayList<>();//下面給出了它的set跟get方法
 private Context mContext;

 public MyVerticalStepView(Context context) {
  this(context, null);
 }

 public MyVerticalStepView(Context context, AttributeSet attrs) {
  this(context, attrs, 0);
 }

 public MyVerticalStepView(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  mContext = context;

 }

 private void init() {
  setOrientation(VERTICAL);
  mDatas = getmDatas();//獲取數(shù)據(jù)
  for (int i = 0; i < mDatas.size(); i++) {
   //獲取布局,注意第二個參數(shù)一定是ViewGroup,否則margin padding之類的屬性將不能使用
   View itemview = LayoutInflater.from(mContext).inflate(R.layout.stepview_item, this, false);
   TextView description = (TextView) itemview.findViewById(R.id.description_tv);
   View line = itemview.findViewById(R.id.line_v);
   ImageView icon = (ImageView) itemview.findViewById(R.id.stepicon_iv);
   description.setText(mDatas.get(i).getDescription());
   //根據(jù)不同狀態(tài)設(shè)置不同圖標
   switch (mDatas.get(i).getCurrentState()) {
    case StepModel.STATE_COMPLETED:
     icon.setImageResource(R.drawable.complted);
     break;
    case StepModel.STATE_DEFAULT:
    //結(jié)尾圖標隱藏豎線
     line.setVisibility(GONE);
     icon.setImageResource(R.drawable.default_icon);
     break;
    case StepModel.STATE_PROCESSING:

     icon.setImageResource(R.drawable.attention);
     break;
   }

   this.addView(itemview);

  }
  requestLayout();//重新繪制布局
  invalidate();//刷新當前界面
 }

 public List<StepModel> getmDatas() {
  return mDatas;
 }

 public void setmDatas(List<StepModel> mDatas) {
  this.mDatas = mDatas;
  init();
 }
}

Activity調(diào)用

public class StepViewDemoActivity extends AppCompatActivity {
 private MyVerticalStepView mStepView;

 @Override
 protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.stepviewlayout);
  mStepView= (MyVerticalStepView) findViewById(R.id.stepview);
   init();
 }
 private void init() {
  List<StepModel> datas=new ArrayList<>();
  StepModel step1=new StepModel("您已提交訂單,等待系統(tǒng)確認",StepModel.STATE_COMPLETED);
  StepModel step2=new StepModel("訂單已確認并打包,預(yù)計12月16日送達",StepModel.STATE_COMPLETED);
  StepModel step3=new StepModel("包裹正在路上",StepModel.STATE_COMPLETED);
  StepModel step4=new StepModel("包裹正在派送",StepModel.STATE_PROCESSING);
  StepModel step5=new StepModel("感謝光臨涂涂女裝(店鋪號85833577),淘寶店鋪,關(guān)注店鋪更多動態(tài)盡在微淘動態(tài)!",StepModel.STATE_DEFAULT);
  datas.add(step1);
  datas.add(step2);
  datas.add(step3);
  datas.add(step4);
  datas.add(step5);
  mStepView.setmDatas(datas);

 }
}

布局

itemview布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="horizontal" android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:paddingTop="5dp"
 android:background="@color/stepviewbg"
 >
<LinearLayout
 android:id="@+id/left"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:orientation="vertical"
 android:paddingRight="10dp"
 android:paddingLeft="10dp"

 >
 <ImageView
  android:id="@+id/stepicon_iv"
  android:layout_width="15dp"
  android:layout_height="15dp"
  android:src="@drawable/attention"
  />
 <View
  android:id="@+id/line_v"
  android:layout_width="2dp"
  android:layout_height="30dp"
  android:background="@color/uncompleted_text_color"
  android:layout_gravity="center_horizontal"
  android:visibility="visible"
  ></View>

</LinearLayout>
 <LinearLayout
  android:layout_toRightOf="@+id/left"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_weight="1"
  android:orientation="vertical"
  android:paddingRight="10dp"
  android:paddingLeft="10dp"
  >
  <TextView
   android:id="@+id/description_tv"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:textSize="18sp"
   android:textColor="@color/uncompleted_text_color"
   android:text="訂單正在派送中"/>

 </LinearLayout>
</RelativeLayout>

stepview布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:layout_width="match_parent"
 android:layout_height="match_parent">
 <com.demo.demo.networkdemo.stepview.MyVerticalStepView
  android:id="@+id/stepview"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">
 </com.demo.demo.networkdemo.stepview.MyVerticalStepView>
</LinearLayout>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論