Skip to content

Commit cfb7700

Browse files
committed
在onStart()时将布局还原,保证在开启画中画模式时不会重复添加View
1 parent 7c6b0ac commit cfb7700

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

library/src/main/java/me/imid/swipebacklayout/lib/SwipeBackLayout.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,15 @@ public void attachToActivity(Activity activity) {
474474
decor.addView(this);
475475
}
476476

477+
public void detachFromActivity(Activity activity) {
478+
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
479+
decorView.removeView(this);
480+
View decorChild = getChildAt(0);
481+
removeView(decorChild);
482+
decorView.addView(decorChild,0);
483+
setContentView(decorChild);
484+
}
485+
477486
@Override
478487
public void computeScroll() {
479488
mScrimOpacity = 1 - mScrollPercent;

library/src/main/java/me/imid/swipebacklayout/lib/app/SwipeBackActivity.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package me.imid.swipebacklayout.lib.app;
33

44
import android.os.Bundle;
5-
import android.support.v4.app.FragmentActivity;
65
import android.support.v7.app.AppCompatActivity;
76
import android.view.View;
87

@@ -22,10 +21,19 @@ protected void onCreate(Bundle savedInstanceState) {
2221
@Override
2322
protected void onPostCreate(Bundle savedInstanceState) {
2423
super.onPostCreate(savedInstanceState);
25-
mHelper.onPostCreate();
2624
}
2725

28-
@Override
26+
@Override protected void onStart() {
27+
super.onStart();
28+
mHelper.onPostCreate();
29+
}
30+
31+
@Override protected void onStop() {
32+
super.onStop();
33+
mHelper.onStop();
34+
}
35+
36+
@Override
2937
public View findViewById(int id) {
3038
View v = super.findViewById(id);
3139
if (v == null && mHelper != null)

library/src/main/java/me/imid/swipebacklayout/lib/app/SwipeBackActivityHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public void onPostCreate() {
3333
mSwipeBackLayout.attachToActivity(mActivity);
3434
}
3535

36+
public void onStop() {
37+
mSwipeBackLayout.detachFromActivity(mActivity);
38+
}
39+
3640
public View findViewById(int id) {
3741
if (mSwipeBackLayout != null) {
3842
return mSwipeBackLayout.findViewById(id);

0 commit comments

Comments
 (0)