2016-10-23 76 views
0

在android支持庫的最近更新中,禁用SwipeRefreshLayout也會重置佈局,而之前它沒有使用。禁用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班和覆蓋setEnabled,但我不能訪問祖父母班'setEnabled那樣。有沒有解決的辦法?

回答

1

如果你把你的類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(); 
     } 
    } 
}