国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android StepView實現物流進度效果

2019-10-22 18:11:08
字體:
來源:轉載
供稿:網友

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

Android,StepView,進度

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

思路

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

代碼

Android,StepView,進度

Model

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

Android,StepView,進度

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

Android,StepView,進度

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

Android,StepView,進度

根據上面分析需要兩個變量,currentState是為了根據狀態設置不同圖標的

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

完整

public class StepModel { public static final String STATE_PROCESSING="PROCESSING";//正在進行的狀態 public static final String STATE_COMPLETED="COMPLETED";//已經完成的狀態 public static final String STATE_DEFAULT="DEFAULT";//結尾的默認狀態 private String description;//當前狀態描述 private String currentState;//當前狀態(上面三個狀態中的一個) 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();//獲取數據  for (int i = 0; i < mDatas.size(); i++) {   //獲取布局,注意第二個參數一定是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());   //根據不同狀態設置不同圖標   switch (mDatas.get(i).getCurrentState()) {    case StepModel.STATE_COMPLETED:     icon.setImageResource(R.drawable.complted);     break;    case StepModel.STATE_DEFAULT:    //結尾圖標隱藏豎線     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調用

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("您已提交訂單,等待系統確認",StepModel.STATE_COMPLETED);  StepModel step2=new StepModel("訂單已確認并打包,預計12月16日送達",StepModel.STATE_COMPLETED);  StepModel step3=new StepModel("包裹正在路上",StepModel.STATE_COMPLETED);  StepModel step4=new StepModel("包裹正在派送",StepModel.STATE_PROCESSING);  StepModel step5=new StepModel("感謝光臨涂涂女裝(店鋪號85833577),淘寶店鋪,關注店鋪更多動態盡在微淘動態!",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>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 漯河市| 金秀| 宁国市| 扶风县| 同江市| 济宁市| 开阳县| 南澳县| 平阳县| 肥西县| 建始县| SHOW| 舟山市| 康平县| 长海县| 西青区| 齐齐哈尔市| 和顺县| 阿鲁科尔沁旗| 南岸区| 连城县| 右玉县| 从江县| 成安县| 大埔县| 太仆寺旗| 乌审旗| 资兴市| 叶城县| 上杭县| 灌云县| 宁强县| 三都| 南投市| 屯昌县| 个旧市| 淮北市| 茂名市| 庆阳市| 五大连池市| 会东县|