关于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);
}
});
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
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);
}
});
}
相关文章推荐
- JDK环境变量配置
- PHPUnit单元测试模拟与桩
- PHP内核之opcode的处理函数查找
- python的tkinter同时呈现两个窗口
- python使用多线程与自定义event更新tinter的内容
- python tkinter 绑定回车键
- 基于zookeeper的分布式Lock及RLock的实现
- C语言中简单函数的运用
- Junit--spring 应用
- Java线程代码
- GitHub和SourceTree入门教程
- Python 3 加密简介
- android studio中把c/c++文件编译成.so库
- SpringBoot集成velocity
- javascipt 中this的学习小节
- php_适配器
- 《Java编程思想第四版》笔记---10章 内部类
- python opencv 提取彩色图像三通道
- 《Java编程思想第四版》笔记---1~9章(2)面向对象特性
- (Spring Boot框架)快速入门