From fc5d5732a0bc0ce81dad225710eb945b9085fffa Mon Sep 17 00:00:00 2001 From: Brook <875428190@qq.com> Date: Wed, 26 Dec 2018 17:20:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../supportlibrary/views/StateLayout.java | 40 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 3fe424b..6041fcd 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ allprojects { 然后在需要使用的模块的build.gradle中添加以下代码 ```groovy dependencies { - implementation 'com.github.Brook007:StateLayout:1.0.1' + implementation 'com.github.Brook007:StateLayout:1.0.2' } ``` diff --git a/library/src/main/java/com/brook/app/android/supportlibrary/views/StateLayout.java b/library/src/main/java/com/brook/app/android/supportlibrary/views/StateLayout.java index 876d81f..d260c53 100644 --- a/library/src/main/java/com/brook/app/android/supportlibrary/views/StateLayout.java +++ b/library/src/main/java/com/brook/app/android/supportlibrary/views/StateLayout.java @@ -182,11 +182,13 @@ public void setNoNetworkViewById(@IdRes int resId) { * @param view */ public void setNoNetworkView(View view) { - StateLayout.LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); - if (layoutParams == null) { + ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); + if (layoutParams != null && layoutParams instanceof LayoutParams) { + ((LayoutParams) layoutParams).stateFlag = NO_NETWORK; + } else { layoutParams = new StateLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + ((LayoutParams) layoutParams).stateFlag = NO_NETWORK; } - layoutParams.stateFlag = NO_NETWORK; view.setLayoutParams(layoutParams); view.setVisibility(View.GONE); this.noNetwork = view; @@ -212,11 +214,13 @@ public void setNoDataViewById(@IdRes int resId) { } public void setNoDataView(View view) { - StateLayout.LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); - if (layoutParams == null) { + ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); + if (layoutParams != null && layoutParams instanceof LayoutParams) { + ((LayoutParams) layoutParams).stateFlag = NO_DATA; + } else { layoutParams = new StateLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + ((LayoutParams) layoutParams).stateFlag = NO_DATA; } - layoutParams.stateFlag = NO_DATA; view.setLayoutParams(layoutParams); view.setVisibility(View.GONE); this.noData = view; @@ -250,11 +254,13 @@ public void setErrorView(@LayoutRes int resId) { * @param view */ public void setErrorView(View view) { - StateLayout.LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); - if (layoutParams == null) { + ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); + if (layoutParams != null && layoutParams instanceof LayoutParams) { + ((LayoutParams) layoutParams).stateFlag = ERROR; + } else { layoutParams = new StateLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + ((LayoutParams) layoutParams).stateFlag = ERROR; } - layoutParams.stateFlag = ERROR; view.setLayoutParams(layoutParams); view.setVisibility(View.GONE); this.error = view; @@ -285,11 +291,13 @@ public void setOnLoadingViewById(@IdRes int resId) { * @param view */ public void setOnLoadingView(View view) { - StateLayout.LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); - if (layoutParams == null) { + ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); + if (layoutParams != null && layoutParams instanceof LayoutParams) { + ((LayoutParams) layoutParams).stateFlag = LOADING; + } else { layoutParams = new StateLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + ((LayoutParams) layoutParams).stateFlag = LOADING; } - layoutParams.stateFlag = LOADING; view.setLayoutParams(layoutParams); view.setVisibility(View.GONE); this.onLoading = view; @@ -320,11 +328,13 @@ public void setSuccessViewById(@IdRes int resId) { * @param view */ public void setSuccessView(View view) { - StateLayout.LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); - if (layoutParams == null) { + ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); + if (layoutParams != null && layoutParams instanceof LayoutParams) { + ((LayoutParams) layoutParams).stateFlag = SUCCESS; + } else { layoutParams = new StateLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + ((LayoutParams) layoutParams).stateFlag = SUCCESS; } - layoutParams.stateFlag = SUCCESS; view.setLayoutParams(layoutParams); view.setVisibility(View.GONE); this.success = view;