您的位置:首页 > 编程语言

关于SwipeRefreshLayout 弹出的问题 进来默认代码初始状态不弹开(就3步)

2016-08-27 00:00 375 查看
摘要: SwipeRefreshLayout,下拉刷新

版权声明:本文为博主原创文章,未经博主允许不得转载。

1、首先重写SwipeRefreshLayout

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;

public class AutoSwipeRefreshLayout extends SwipeRefreshLayout {

private boolean mMeasured = false;
private boolean mPreMeasureRefreshing = false;

@Override
public void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (!mMeasured) {
mMeasured = true;
setRefreshing(mPreMeasureRefreshing);
}
}

@Override
public void setRefreshing(final boolean refreshing) {
if (mMeasured) {
super.setRefreshing(refreshing);
} else {
mPreMeasureRefreshing = refreshing;
}
}

public AutoSwipeRefreshLayout(Context context) {
super(context);
}

public AutoSwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

}

2、布局文件

<包名.wiget.AutoSwipeRefreshLayout
android:id="@+id/simu_root"
android:layout_width="match_parent"
android:layout_height="match_parent" >


<ExpandableListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="@color/transparent"
android:scrollbars="none" >
</ExpandableListView>
</包名.wiget.AutoSwipeRefreshLayout>


3、之后就在 view 创建的时候 写以下的代码就好

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mSwipeLayout.setProgressViewOffset(false, 0, 30);

mSwipeLayout.getViewTreeObserver()
.addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mSwipeLayout
.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
mSwipeLayout.setRefreshing(true);
}
});
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: