compile 'com.android.support:support-v4:22.1.1'
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="@+id/id_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</android.support.v4.widget.SwipeRefreshLayout>
<string-array name="singer_names">
<item>周杰伦</item>
<item>那英</item>
<item>刘德华</item>
<item>张学友</item>
<item>许巍</item>
<item>朴树</item>
<item>陈奕迅</item>
<item>A_Lin</item>
<item>杨宗纬</item>
</string-array>
setContentView(R.layout.activity_main);
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.id_swipe_refresh);
mListView =(ListView)findViewById(R.id.id_listview);
String[] singer = getResources().getStringArray(R.array.singer_names);
mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, singer);
mListView.setAdapter((ListAdapter) mAdapter);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshContent();
}
});
private void refreshContent(){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, getSingerNames());
mListView.setAdapter((ListAdapter) mAdapter);
//设置刷新加载效果的icon是否继续显示
mSwipeRefreshLayout.setRefreshing(false);
}
},2000);
}
private List<String> getSingerNames() {
List<String> newCatNames = new ArrayList<String>();
for (int i = 0; i < mSingerNames.length; i++) {
int randomCatNameIndex = new Random().nextInt(mSingerNames.length - 1);
newCatNames.add(mSingerNames[randomCatNameIndex]);
}
return newCatNames;
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ImprovedSwipeLayoutAttrs">
<attr name="scrollableChildId" format="reference" />
</declare-styleable>
</resources>
<com.goach.palm.demo.ImprovedSwipeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:isl="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/md_blue_grey_50"
isl:scrollableChildId="@+id/list_statuses"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list_statuses"
android:minHeight="?android:attr/listPreferredItemHeight"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:clipToPadding="false"
android:divider="@android:color/transparent"
android:dividerHeight="12dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="2234544543"
/>
</FrameLayout>
</com.goach.palm.demo.ImprovedSwipeLayout>
public class ImprovedSwipeLayout extends SwipeRefreshLayout {
private static final String TAG = ImprovedSwipeLayout.class.getCanonicalName();
private int mScrollableChildId;
private View mScrollableChild;
public ImprovedSwipeLayout(Context context) {
this(context, null);
}
public ImprovedSwipeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.ImprovedSwipeLayoutAttrs);
mScrollableChildId = a.getResourceId(R.styleable.ImprovedSwipeLayoutAttrs_scrollableChildId, 0);
mScrollableChild = findViewById(mScrollableChildId);
a.recycle();
}
@Override
public boolean canChildScrollUp() {
ensureScrollableChild();
if (android.os.Build.VERSION.SDK_INT < 14) {
if (mScrollableChild instanceof AbsListView) {
final AbsListView absListView = (AbsListView) mScrollableChild;
return absListView.getChildCount() > 0
&& (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
.getTop() < absListView.getPaddingTop());
} else {
return mScrollableChild.getScrollY() > 0;
}
} else {
return ViewCompat.canScrollVertically(mScrollableChild, -1);
}
}
private void ensureScrollableChild() {
if (mScrollableChild == null) {
mScrollableChild = findViewById(mScrollableChildId);
}
}
}
lView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (firstVisibleItem == 0)
swipeView.setEnabled(true);
else
swipeView.setEnabled(false);
}
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有