Skip to content

Commit

Permalink
修复BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
Brook committed Dec 26, 2018
1 parent 903de29 commit fc5d573
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fc5d573

Please sign in to comment.