Skip to content

Commit

Permalink
fix: #15 when parent.getParent() is ConstraintLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
nukc committed Sep 18, 2018
1 parent bd005dd commit cc07875
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## ChangeLog

#### Version 1.5.3
fix #15 when parent.getParent() is ConstraintLayout

#### Version 1.5.0
Supported wrap view

Expand Down
2 changes: 1 addition & 1 deletion README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ StateView is an invisible, zero-sized View that can be used to lazily inflate lo
add the dependency to your build.gradle:

```groovy
compile 'com.github.nukc.stateview:library:1.5.2'
compile 'com.github.nukc.stateview:library:1.5.3'
// animator providers
compile 'com.github.nukc.stateview:animations:1.0.1'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ StateView 一个轻量级的控件, 继承自 `View`, 吸收了 `ViewStub` 的


```groovy
compile 'com.github.nukc.stateview:library:1.5.2'
compile 'com.github.nukc.stateview:library:1.5.3'
// animator providers
compile 'com.github.nukc.stateview:animations:1.0.1'
Expand Down
2 changes: 1 addition & 1 deletion bintray.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def siteUrl = 'https://github.com/nukc/StateView' // 项目的主页
def gitUrl = 'https://github.com/nukc/StateView.git' // Git仓库的url

group = "com.github.nukc.stateview"
version = "1.5.2"
version = "1.5.3"

install {
repositories.mavenInstaller {
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 27
versionCode 23
versionName "1.5.2"
versionCode 24
versionName "1.5.3"
}
buildTypes {
release {
Expand Down
10 changes: 7 additions & 3 deletions library/src/main/java/com/github/nukc/stateview/StateView.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ public static StateView inject(@NonNull ViewGroup parent, boolean hasActionBar)
} else {
FrameLayout root = new FrameLayout(parent.getContext());
root.setLayoutParams(parent.getLayoutParams());
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
parent.setLayoutParams(layoutParams);

if (viewParent instanceof ViewGroup) {
ViewGroup rootGroup = (ViewGroup) viewParent;
Expand All @@ -183,6 +180,13 @@ public static StateView inject(@NonNull ViewGroup parent, boolean hasActionBar)
// 然后替换成新的
rootGroup.addView(root);
}

// if viewParent is ConstraintLayout, setLayoutParams must after rootGroup.removeView(parent);
// @see at at android.support.constraint.ConstraintLayout.getViewWidget
// @see at android.support.constraint.ConstraintLayout.onViewRemoved
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
parent.setLayoutParams(layoutParams);
root.addView(parent);
parent = root;
}
Expand Down

0 comments on commit cc07875

Please sign in to comment.