禁用 SwipeRefreshLayout 会重置布局
Disabling SwipeRefreshLayout resets the layout
在 android 支持库的最新更新中,禁用 SwipeRefreshLayout 也会重置布局,而以前没有使用过。
void reset() {
mCircleView.clearAnimation();
mProgress.stop();
mCircleView.setVisibility(View.GONE);
setColorViewAlpha(MAX_ALPHA);
// Return the circle to its start position
if (mScale) {
setAnimationProgress(0 /* animation complete and view is hidden */);
} else {
setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCurrentTargetOffsetTop,
true /* requires update */);
}
mCurrentTargetOffsetTop = mCircleView.getTop();
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (!enabled) {
reset();
}
}
我不想在禁用布局时调用 reset
,但我找不到直接的方法。我想过扩展 SwipeRefreshLayout
class 并覆盖 setEnabled
但我无法通过这种方式访问祖父母 class' setEnabled
。有解决办法吗?
如果你把你的 class 放到 android.support.v4.widget
,你可以这样做:
package android.support.v4.widget;
import android.content.Context;
import android.util.AttributeSet;
/**
*
*/
public class MySwipeRefreshLayout extends SwipeRefreshLayout {
private boolean settingEnabled = false;
public MySwipeRefreshLayout(Context context) {
super(context);
}
public MySwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setEnabled(boolean enabled) {
try {
settingEnabled = true;
super.setEnabled(enabled);
} finally {
settingEnabled = false;
}
}
@Override
void reset() {
if (!settingEnabled) {
super.reset();
}
}
}
在 android 支持库的最新更新中,禁用 SwipeRefreshLayout 也会重置布局,而以前没有使用过。
void reset() {
mCircleView.clearAnimation();
mProgress.stop();
mCircleView.setVisibility(View.GONE);
setColorViewAlpha(MAX_ALPHA);
// Return the circle to its start position
if (mScale) {
setAnimationProgress(0 /* animation complete and view is hidden */);
} else {
setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCurrentTargetOffsetTop,
true /* requires update */);
}
mCurrentTargetOffsetTop = mCircleView.getTop();
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (!enabled) {
reset();
}
}
我不想在禁用布局时调用 reset
,但我找不到直接的方法。我想过扩展 SwipeRefreshLayout
class 并覆盖 setEnabled
但我无法通过这种方式访问祖父母 class' setEnabled
。有解决办法吗?
如果你把你的 class 放到 android.support.v4.widget
,你可以这样做:
package android.support.v4.widget;
import android.content.Context;
import android.util.AttributeSet;
/**
*
*/
public class MySwipeRefreshLayout extends SwipeRefreshLayout {
private boolean settingEnabled = false;
public MySwipeRefreshLayout(Context context) {
super(context);
}
public MySwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setEnabled(boolean enabled) {
try {
settingEnabled = true;
super.setEnabled(enabled);
} finally {
settingEnabled = false;
}
}
@Override
void reset() {
if (!settingEnabled) {
super.reset();
}
}
}