Comments (3)
from swipetoloadlayout.
#32可以显示,但是我是想 在listview没有数据时候显示一个emptyView 这个emptyView 不是在listview下面 而是可以一起滑动的 可以做到吗
from swipetoloadlayout.
- Create a Custom SwipeToLoadLayout
public class MySwipeToLoadLayout extends SwipeToLoadLayout {
private View mTargetView;
public MySwipeToLoadLayout(Context context) {
super(context);
}
public MySwipeToLoadLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MySwipeToLoadLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void setTargetView(View targetView) {
this.mTargetView = targetView;
}
@Override
protected boolean canChildScrollUp() {
return ViewCompat.canScrollVertically(this.mTargetView, -1);
}
@Override
protected boolean canChildScrollDown() {
return ViewCompat.canScrollVertically(this.mTargetView, 1);
}
}
- layout
<?xml version="1.0" encoding="utf-8"?>
<com.aspsine.googlestyledemo.MySwipeToLoadLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipeToLoadLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:load_more_final_drag_offset="@dimen/load_more_final_offset_google"
app:refresh_final_drag_offset="@dimen/refresh_final_offset_google"
app:swipe_style="classic"
tools:context="com.aspsine.googlestyledemo.MainActivity">
<include
android:id="@id/swipe_refresh_header"
layout="@layout/layout_google_hook_header" />
<FrameLayout
android:id="@id/swipe_target"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/ivEmpty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@mipmap/ic_launcher"/>
</FrameLayout>
<include
android:id="@id/swipe_load_more_footer"
layout="@layout/layout_google_hook_footer" />
</com.aspsine.googlestyledemo.MySwipeToLoadLayout>
- activity
public class MainActivity extends AppCompatActivity implements OnRefreshListener, OnLoadMoreListener{
MySwipeToLoadLayout swipeToLoadLayout;
private View emptyView;
ArrayAdapter<String> mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipeToLoadLayout = (MySwipeToLoadLayout) findViewById(R.id.swipeToLoadLayout);
ListView listView = (ListView) findViewById(R.id.listView);
emptyView = findViewById(R.id.ivEmpty);
listView.setEmptyView(emptyView);
// here set the listView as our new targetView
swipeToLoadLayout.setTargetView(listView);
swipeToLoadLayout.setOnRefreshListener(this);
swipeToLoadLayout.setOnLoadMoreListener(this);
mAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_expandable_list_item_1);
listView.setAdapter(mAdapter);
autoRefresh();
}
@Override
public void onRefresh() {
swipeToLoadLayout.postDelayed(new Runnable() {
@Override
public void run() {
swipeToLoadLayout.setRefreshing(false);
mAdapter.add("REFRESH:\n" + new Date());
}
}, 2000);
}
@Override
public void onLoadMore() {
swipeToLoadLayout.postDelayed(new Runnable() {
@Override
public void run() {
swipeToLoadLayout.setLoadingMore(false);
mAdapter.add("LOAD MORE:\n" + new Date());
}
}, 2000);
}
private void autoRefresh() {
swipeToLoadLayout.post(new Runnable() {
@Override
public void run() {
swipeToLoadLayout.setRefreshing(true);
}
});
}
}
All done.
from swipetoloadlayout.
Related Issues (20)
- ListView emptyView,求指教 怎么处理。 HOT 1
- maven库拉不下来,能不能换到jcenter库
- 请问如何配置下拉阻力系数?下拉时越往下移动距离越小 HOT 1
- 事件拦截!!!急 HOT 3
- 瀑布流的上拉刷新,如何处理才能不显示不对齐的空白
- 正在刷新的状态下,reclycleview居然可以上滑 HOT 1
- 当嵌套ListView发现滑动冲突问题 HOT 1
- 上拉或下拉 刷新时 SwipeTrigger void onMove(int y, boolean isComplete, boolean automatic);
- onMove(int y, boolean isComplete, boolean automatic);建议还是改为 float 类型 做一些效果时 距离精度丢失了
- 下拉刷新刷新完成有时候头布局一直在转
- 崩!
- 有个问题
- 作者这个库不维护了吗
- 子控件大小设置为自适应,SwipeToLoadLayout,子控件内容发生变化,但控件大小无法改变 HOT 1
- 最新版的isRefreshing()接口在下拉刷新后一直显示为true,不能用于判断刷新状态。
- CoordinatorLayout嵌套SwipeToLoadLayout出现滑动冲突 HOT 3
- 在fragment生命周期onActivityCreated中发生null pointer exception
- swipe_target should chagne to android:tag
- CoordinatorLayout
- 当recyclerview添加了footerview之后又隐藏的话不能上拉加载更多
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swipetoloadlayout.