我有Fragment一个SwipeRefreshLayout,然后RecyclerView为孩子.提交片段时,它会开始与服务器通信以检索某些数据并填充将为RecyclerView提供服务的CustomAdapter.
用户可以通过向下滑动或按ActionBar上的按钮来刷新内容.在后一种情况下,我手动调用swipeRefreshLayout.setRefreshing(true).所以到现在为止没有麻烦.
在第一次加载RecyclerView(onStart())期间手动调用刷新状态时出现问题.进度指示器没有显示,我假设因为RecyclerView仍然是空的,因为它需要几秒钟来检索所有数据......
我留给你一些代码.
片段代码:
public class MyFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View mView = inflater.inflate(R.layout.fragment_stop, container, false);
mRecyclerView = (RecyclerView) mView.findViewById(R.id.recyclerView1);
mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(),
DividerItemDecoration.VERTICAL_LIST));
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
//SwipeRefreshLayout retrieved and configured
swipeLayout = (SwipeRefreshLayout) mView.findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorSchemeResources(
R.color.primaryColor,
R.color.cyan_500,
R.color.light_green_500,
R.color.amber_500);
return mView;
}
...
@Override
public void onStart() {
super.onStart();
executeSchedule(); //First execution and data …Run Code Online (Sandbox Code Playgroud) android android-appcompat swiperefreshlayout android-recyclerview
在执行刷卡刷新视图之前,回收器视图工作正常但不是每当我尝试向下滚动回收器视图时刷卡刷新干扰并阻碍滚动运动.
以下是该问题的屏幕截图:
(注意,当回收器视图向下滚动时,滑动刷新布局会出现)
这是我的布局片段:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:wheel="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/availableTaskRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
<RelativeLayout
android:id="@+id/progress_wheel"
android:visibility="gone"
tools:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal|center_vertical"
android:background="@color/transparentLoaderBackground">
<com.pnikosis.materialishprogress.ProgressWheel
android:layout_width="50dp"
android:layout_height="50dp"
wheel:matProg_barColor="@color/white"
wheel:matProg_barWidth="1dp"
wheel:matProg_progressIndeterminate="true"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/no_available_tasks"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility = "visible"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No tasks currently available. Pull to refresh"
android:layout_centerInParent="true"
android:padding="16dp"
android:gravity="center_horizontal"
android:textSize="18sp"/>
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
下面是我片段的代码:
package com.packrboy.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import …Run Code Online (Sandbox Code Playgroud) android swiperefreshlayout android-recyclerview recyclerview-layout
我使用的是NestedScrollWebView(在很大程度上受到影响NestedScrollView),这可以解决许多已知 问题与使用相关联WebView的CoordinatorLayout.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="enterAlways|scroll|snap">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:titleTextAppearance="@style/TextAppearance.AppCompat.Subhead"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:visibility="gone"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>
</FrameLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<com.example.app.widget.NestedScrollWebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
这些NestedScrollWebView作品很好用AppBarLayout和enterAlways|scroll|snap滚动标志,但不是很好SwipeRefreshLayout.
我删除了以下行NestedScrollWebView:
setOverScrollMode(WebView.OVER_SCROLL_NEVER);
Run Code Online (Sandbox Code Playgroud)
这样可以确保视图不会显示在滚动指示器上.我想要显示滚动指示符,但即使启用了过度滚动,也不会出现以下情况.
根据我的理解,SwipeRefreshLayout应该拦截导致刷新指示符被拖动的任何触摸事件(基于其实现onInterceptTouchEvent()).SwipeRefreshLayout也拒绝任何requestDisallowInterceptTouchEvent()已启用嵌套滚动的子项; 这是真的NestedScrollWebView.因此,应按 …
android swiperefreshlayout android-touch-event android-nestedscrollview
我正在尝试在片段中实现SwipeRefreshLayout。它看起来创建正确,但是我继续出现错误:
Caused by: android.view.InflateException: Binary XML file line #2:
Binary XML file line #2: Error inflating class
android.support.v4.widget.SwipeRefreshLayout
Caused by: android.view.InflateException: Binary XML file line #2:
Error inflating class android.support.v4.widget.SwipeRefreshLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class
"android.support.v4.widget.SwipeRefreshLayout" on path:
DexPathList[[zip file "/data/app/com.weather.rainy-
2/base.apk"],nativeLibraryDirectories=[/data/app/com.weather.rainy-
2/lib/x86, /system/lib, /vendor/lib]]
Run Code Online (Sandbox Code Playgroud)
我真的不知道是什么原因造成的。
我用于实现SwipeRefreshLayout的片段布局:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipeToRefresh4Maps"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/topRL4Maps"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_gradient_purple"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="64dp"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="64dp"
tools:context="com.weather.rainy.ui.MapsActivity">
<TextView
android:id="@+id/yourLocationLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="@+string/your_location"
android:textColor="@android:color/white"
android:textSize="24sp" />
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我有一个AppBar和RecyclerViewin CoordiantorLayout。SwipeToRefresh 必须全屏显示,但RecyclerView不能向下滚动。
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="128dp"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
如何在没有库的协调器布局中添加全屏下拉刷新。
android swiperefreshlayout android-recyclerview android-coordinatorlayout android-appbarlayout
我使用的是android.support.v4.widget.SwipeRefreshLayout带android.support.v7.widget.RecyclerView.
在片段视图创建中,我需要显示SwipeRefreshLayout动画.但是当我打电话时setRefreshing(true)没有任何反应 但是当我刷新数据动画的变化时.
我想如果没有孩子,动画就不会显示出来SwipeRefreshLayout.
如何以最佳方式显示此动画?
每次我向上或向下滚动列表时,我都会隐藏(或取消隐藏)某些视图OnScrollListener.这是附在我身上的代码ListView.
lv.setOnScrollListener(new OnScrollListener() {
private int mLastFirstVisibleItem;
private boolean mIsScrollingUp = true;
private LinearLayout ll = (LinearLayout) getActivity()
.findViewById(R.id.llSearchPlaces);
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (view.getId() == lv.getId()) {
final int currentFirstVisibleItem = lv
.getFirstVisiblePosition();
if (currentFirstVisibleItem > mLastFirstVisibleItem) {
if (mIsScrollingUp == true) {
mIsScrollingUp = false;
Log.i("a", "scrolling down...");
floatingActionButton.hide();
Animation animation = new TranslateAnimation(0, 0,
0, 200); …Run Code Online (Sandbox Code Playgroud) 我实现了一个SwipeRefreshLayout使用a RecyclerView,我需要在我期间禁用我的适配器项OnRefreshListener.
我尝试了以下方法,但点击正常发生:
mRecyclerView.setEnabled(false);
mRecyclerView.setClickable(false);
Run Code Online (Sandbox Code Playgroud) java android android-support-library swiperefreshlayout android-recyclerview
我在我的应用中使用了刷卡刷新布局.它工作但我想在刷卡布局边缘前100 px中设置进度条的位置.我不想使用它的默认位置.我怎样做?谢谢
SwipeRefreshLayout不起作用(动画未示出,onRefresh不叫)时在第一项RecyclerView中的SwipeRefreshLayout具有零高度。
你可以在 Github 上查看一个测试项目来展示这一点。
我的问题是:可以避免这种影响吗?在我的实际工程中,由于情况没有在我的手(广告库)我的清单中的第一项将有时有高度0,所以将其设置为View.GONE或高度1是不是一种选择。