Ⅰ android 為什麼swiperefreshlayout刷新動畫是一跟線條
ViewPager是Android中提供的頁面切換的控制項,SwipeRefreshLayout是Android提供的下拉刷新控制項,通過SwipeRefreshLayout可以很簡單的實現下拉刷新的功能,但是如果SwipeRefreshLayout的子view中如果包含了ViewPager,會發現滑動ViewPager的時候,很容易引起SwipeRefreshLayout的下拉刷新操作為了解決這個沖突可以這樣實現
1 viewPager.setOnTouchListener(new View.OnTouchListener() {
2 @Override
3 public boolean onTouch(View v, MotionEvent event) {
4 switch (event.getAction()) {
5 case MotionEvent.ACTION_MOVE:
6 swipeRefreshLayout.setEnabled(false);
7 break;
8 case MotionEvent.ACTION_UP:
9 case MotionEvent.ACTION_CANCEL:
10 swipeRefreshLayout.setEnabled(true);
11 break;
12 }
13 return false;
14 }
15 });
ViewPager,設置OnTouchListener,裡面當ACTION_MOVE的時候設置SwipeRefreshLayout不可用,當ACTION_UP或者ACTION_CANCEL的時候設置SwipeRefreshLayout可以,就可以解決這個沖突了
Ⅱ android smartrefreshlayout刷新中怎麼添加自定義的界面
一般的消息列表為ListView類型,將list載入到adapter中,再將adapter載入到ListView中,從而實現消息列表的展示。而下拉刷新要求給消息列表加一個頭部,其中有圖片(向上/向下箭頭)和提示字樣(下拉刷新/松開刷新)
Ⅲ android 如何將swiperefreshlayout刷新動畫能定製嗎
在layout中添加SwipeRefreshLayout
1 <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 android:id="@+id/swipe_container"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent" >
5
6 <ScrollView
7 android:layout_width="match_parent"
8 android:layout_height="wrap_content" >
9
10 <TextView
11 android:id="@+id/textView1"
12 android:layout_width="match_parent"
13 android:layout_height="wrap_content"
14 android:gravity="center"
15 android:paddingTop="10dp"
16 android:text="@string/swipe_to_refresh"
17 android:textSize="20sp"
18 android:textStyle="bold" />
19 </ScrollView>
20
21 </android.support.v4.widget.SwipeRefreshLayout>
在Activity中使用:
1 tv = (TextView)findViewById(R.id.textView1);
2 swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipe_container);
3 //設置刷新時動畫的顏色,可以設置4個
4 swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
5 swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
6
7 @Override
8 public void onRefresh() {
9 tv.setText("正在刷新");
10 // TODO Auto-generated method stub
11 new Handler().postDelayed(new Runnable() {
12
13 @Override
14 public void run() {
15 // TODO Auto-generated method stub
16 tv.setText("刷新完成");
17 swipeRefreshLayout.setRefreshing(false);
18 }
19 }, 6000);
20 }
21 });
PS:setColorScheme()已經棄用,使用setColorSchemeResources()來設置顏色。
Ⅳ android swiperefreshrecyclerview 怎麼實時刷新
使用官方的刷新控制項SwipeRefreshLayout來實現下拉刷新,當RecyclerView滑到底部實現下拉載入(進度條效果用RecyclerView載入一個布局實現) 喜歡Android RecyclerView實現下拉刷新和上拉載入更多的網友,不妨看看下面這篇文章: [js事件冒泡與事件捕獲詳解]/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/tv_item_footer_load_more" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dp" android:gravity="center" android:text="上拉載入更多" /> <ProgressBar android:id="@+id/pb_item_footer_loading" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dp"android:visibility="gone"/></RelativeLayout>適配器 public class RecyclerAdapter extends RecyclerViewIdNameLoadMore; } } /** * 獲取數據集加上一個footer的數量 */ @Override public int getItemCount() { return dataList_item_id); tvName = (TextView) itemView_item_name); } } /** * footer的ViewHolder */ public static class FooterViewHolder extends ViewHolder { private TextView tvLoadMore; private ProgressBar pbLoading; public FooterViewHolder(View itemView) { super(itemView); tvLoadMore = (TextView) itemView_item_footer_load_more); pbLoading = (ProgressBar) itemView.findViewById(R.id.pb_item_footer_loading); } } /** * 顯示正在載入的進度條,滑動到底部時,調用該方法,上拉就顯示進度條,隱藏"上拉載入更多" */ public void showLoading() { if (pbLoading != null && tvLoadMore != null) { pbLoading.setVisibility(View.VISIBLE); tvLoadMore.setVisibility(View.GONE); } } /** * 顯示上拉載入的文字,當數據載入完畢,調用該方法,隱藏進度條,顯示“上拉載入更多” */ public void showLoadMore() { if (pbLoading != null && tvLoadMore != null) { pbLoading.setVisibility(View.GONE); tvLoadMore.setVisibility(View.VISIBLE); } }}
Ⅳ android在framelayout怎麼實現下拉刷新
下拉刷新 android sdk中幾年前就有了SwipeRefreshLayout 比第三方的庫用法簡單100倍
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(true);
Ⅵ android 動態添加控制項 怎麼刷新頁面
1、動態添加的時候為組件設置id,刪除的時候根據id查找到對應組件,然後刪除
2、根據父節點,獲取所有父組件下的子組件,然後依次刪除。
示例:
protected View createView() {//動態添加組件
Button btn = new Button(this);//動態創建按鈕
btn.setId(index++);
btn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
btn.setText("aaaaaa" + index);
return btn;
}
private void removeView() {//動態刪除組件(按鈕)
//獲取linearlayout子view的個數
int count = linearLayout.getChildCount();
//研究整個LAYOUT布局,第0位的是含add和remove兩個button的layout
//第count-1個是那個文字被置中的textview
//因此,在remove的時候,只能操作的是0<location<count-1這個范圍的
//在執行每次remove時,我們從count-2的位置即textview上面的那個控制項開始刪除~
if (count - 2 > 0) {
//count-2>0用來判斷當前linearlayout子view數多於2個,即還有我們點add增加的button
linearLayout.removeViewAt(count - 2);
}
}
Ⅶ android swiperefreshlayout怎麼禁止下拉刷新
不要下拉刷新直接不用它不就完了 或者試試setEnabled(false
Google提供了一個官方的下拉刷新控制項SwipeRefreshLayout,個人感覺還不錯!見慣了傳統的下拉刷新,這個反而給人耳目一新的感覺(Gmail郵箱已經使用這種下拉刷新了)。
SwipeRefreshLayout在V4包下,對應的V4 Demo中也有相應的例子。
SwipeRefreshLayout只能有一個直接子View,可能是一個ListView或一個Layout或其他需要刷新的組件。
setOnRefreshListener 用於監聽刷新的動作。SwipeRefreshLayout 下拉,就會有刷新的效果出來,觸發該監聽。
如果需要一個刷新的動畫,setRefreshing(true), 停: setRefreshing(false)
如果要禁用刷新動畫和手勢響應,ssetEnable(false),恢復:setEnable(true)
Google也在官方網站給出了V4的兼容包:
Ⅷ android swiperefreshlayout怎麼禁止下拉刷新
不要下拉刷新直接不用它不就完了
或者試試setEnabled(false
Google提供了一個官方的下拉刷新控制項SwipeRefreshLayout,個人感覺還不錯!見慣了傳統的下拉刷新,這個反而給人耳目一新的感覺(Gmail郵箱已經使用這種下拉刷新了)。
SwipeRefreshLayout在V4包下,對應的V4
Demo中也有相應的例子。
SwipeRefreshLayout只能有一個直接子View,可能是一個ListView或一個Layout或其他需要刷新的組件。
setOnRefreshListener
用於監聽刷新的動作。SwipeRefreshLayout
下拉,就會有刷新的效果出來,觸發該監聽。
如果需要一個刷新的動畫,setRefreshing(true),
停:
setRefreshing(false)
如果要禁用刷新動畫和手勢響應,ssetEnable(false),恢復:setEnable(true)
Google也在官方網站給出了V4的兼容包:
相關API如下:
Ⅸ Android SwipeRefreshLayout刷新卡頓問題
網頁鏈接網頁鏈接
附上鏈接,大哥小事搜網路,大事搜網路,再大點搜Google。
用搜不用問,是一個程序員基本的規范
Ⅹ Android 控制項smartRefeshLayout只要下拉刷新,禁止上拉載入
一.導入依賴
在app-mole中添加RecycleView和SmartRefreshLayout的依賴
//recyclerview implementation 'com.android.support:recyclerview-v7:26.1.0' implementation 'com.android.support:design:26.1.0' //SmartRefreshLayout implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.4-7' implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.4-7'
二.在mainActivity中添加xml布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout 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:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.freshdemo.MainActivity"android:orientation="vertical"><com.scwang.smartrefresh.layout.SmartRefreshLayoutandroid:id="@+id/refreshLayout"android:layout_width="match_parent"android:layout_height="match_parent"app:srlAccentColor="#00000000"app:srlPrimaryColor="#00000000"app:srlEnablePreviewInEditMode="true"><android.support.v7.widget.RecyclerViewandroid:id="@+id/rv"android:layout_width="match_parent"android:layout_height="match_parent"/></com.scwang.smartrefresh.layout.SmartRefreshLayout></LinearLayout>
這是SmartRefreshLayout的基本布局,其中:
app:srlAccentColor="#00000000"//設置Header主題顏色 app:srlPrimaryColor="#00000000"//設置Footer主題顏色 app:srlEnablePreviewInEditMode="true"//開啟和關閉預覽功能
三.MainActivity中初始化和刷新載入事件
private RecyclerView mRecyclerView; private RefreshLayout mRefreshLayout; //初始化 mRecyclerView=findViewById(R.id.rv); mRefreshLayout = findViewById(R.id.refreshLayout); //刷新 mRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(RefreshLayout refreshlayout) { mData.clear(); mNameAdapter.notifyDataSetChanged(); refreshlayout.finishRefresh(); } }); //載入更多 mRefreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() { @Override public void onLoadmore(RefreshLayout refreshlayout) { for(int i=0;i<30;i++){ mData.add("小明"+i); } mNameAdapter.notifyDataSetChanged(); refreshlayout.finishLoadmore(); } });
四.運行效果
SmartRefreshLayout運行的默認效果如下
image.png
他們的包路徑是:
com.scwang.smartrefresh.header.BezierCircleHeadercom.scwang.smartrefresh.header.DeliveryHeader//以下類似,在此省略//......
六.自定義Header和Footer
當然SmartRefreshLayout還支持自定義Header和Footer
具體可以參考官網中的自定義Header
SmartRefreshLayout關於屬性這一塊也是有很多可以設置的,大家依然可以去SmartRefreshLayout官網查看更多使用細則,這里就不展開講解了
今天就講到這里了,謝謝大家。