我实现了SwipeRefreshLayout和ViewPager我的应用程序,但有一个大麻烦:每当我要去刷卡左/右滚动页面之间切换过于敏感.稍微向下滑动也会触发SwipeRefreshLayout刷新.
我想设置水平滑动开始时的限制,然后强制水平直到滑动结束.换句话说,当手指水平移动时,我想取消垂直滑动.
这个问题只发生在ViewPager,如果我向下滑动并SwipeRefreshLayout触发刷新功能(显示条形图)然后我水平移动手指,它仍然只允许垂直滑动.
我试图扩展ViewPager课程,但它根本不起作用:
public class CustomViewPager extends ViewPager {
public CustomViewPager(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean in = super.onInterceptTouchEvent(ev);
if (in) {
getParent().requestDisallowInterceptTouchEvent(true);
this.requestDisallowInterceptTouchEvent(true);
}
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
布局xml:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/viewTopic"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.myapp.listloader.foundation.CustomViewPager
android:id="@+id/topicViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激,谢谢
我实现了新的SwipeRefreshLayout成分在我的应用程序,它与任何垂直意见工作得很好,比如ListView,GridView和ScrollView.
它在水平视图中表现得很糟糕,比如HorizontalScrollView.向右或向左滚动时,SwipeRefreshLayout视图会缓存触摸,阻止HorizontalScrollView接收并开始垂直滚动以执行刷新.
我尝试解决这个问题,因为我之前解决了ScrollView与ViewPager内部垂直问题,使用requestDisallowInterceptTouchEvent但它没有用.我还注意到,在原始SwipeRefreshLayout类中重写此方法而不返回super.谷歌的开发者留下了评论" //Nope.":)
因为SwipeRefreshLayout组件相对较新,我找不到修复水平滚动问题的解决方案,同时仍然允许滑动刷新视图以跟踪和处理垂直滚动,所以我想我会分享我的解决方案,希望它会让人节省一个小时或两个.
如何WebView在Android中实现Scroll Listener
我试过这个,但它没有调用我Log.i滚动webview.
package com.example.webview.full.width;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.webkit.WebView;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
public class scorllableWebview extends WebView implements OnScrollListener {
Context ctx;
AttributeSet atrs;
public scorllableWebview(Context context) {
super(context);
ctx = context;
}
public scorllableWebview(Context context, AttributeSet atters){
super(context, atters);
ctx = context;
atrs = atters;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
Log.i("onScroll", "Called");
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
Log.i("onScrollStateChanged", …Run Code Online (Sandbox Code Playgroud) 我已经实现SwipeRefreshLayout了我的应用程序,但它只能容纳一个应该是listview的直接子项.我试图找出如何将空文本视图添加到以下工作XML文件:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/listViewConversation"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1dp" />
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
将其包装在线性/相对布局中会使其失灵,因为当您想要向下滑动列表视图时,列表视图将始终更新.我能想到的一种方法是以编程方式进行此操作,但我想这不是最好的选择.
您可以使用本教程学习如何实现它:滑动以刷新GUIDE
所以基本上它一切正常,但我想添加一个空视图,当listview为空时显示一条消息.
我将在我的webview上添加pull刷新,以便刷新我的webview.我在这个页面上看到了所有问题,但我找不到添加拉动刷新的好方法......
Mainactivity.java
package com.vvhvb.hesselfeenstra.vvheerenveenseboys;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url ="http://heerenveenseboys.nl/";
WebView view=(WebView) this.findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.getSettings().setBuiltInZoomControls(true);
view.getSettings().setDisplayZoomControls(false);
view.setWebViewClient(new WebViewClient());
view.loadUrl(url);
}
}
Run Code Online (Sandbox Code Playgroud)
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.vvhvb.hesselfeenstra.vvheerenveenseboys.MainActivity"
tools:showIn="@layout/activity_main">
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/webView"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我希望有人能帮助我并为我解决这个问题.
我在FrameLayout中有一个WebView,因为我正在创建一个浏览器来添加标签.FrameLayout位于SwipeRefreshLayout内.
问题:每当我在WebView中快速滚动内容时,工具栏后面会出现刷新图标.它应该只在WebView内容位于顶部时才会发生.它与FrameLayout有关,当我删除它时,问题就消失了.
布局如下所示:
<SwipeRefreshLayout
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/webViewFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud) android android-webview swiperefreshlayout android-framelayout
我试图使用webview的滚动位置来确定SwipeRefreshLayout是否应该能够刷新,除了一些网站,例如https://jobs.lever.co/memebox,getScrollY()总是返回0.有没有办法确保我会总是得到正确的滚动位置?
我做了一个新闻阅读器应用程序(WebView).我不知道如何在我的应用中添加一个拉动刷新.我是一名刚刚参加编程的学生(Learner/n00b)任何人都可以告诉我要添加的内容或者我必须在此发布的java类或xml代码,以便您可以帮助我.
java android android-webview android-studio android-studio-2.2