如何在android中实现下拉刷新?(How to implement pull down refresh in android?)

编程入门 行业动态 更新时间:2024-10-10 02:17:36
如何在android中实现下拉刷新?(How to implement pull down refresh in android?)

目前我正在研究一个简单的带有framelayout的webview的片段,问题是,我想做一些像下拉刷新 (就像列表视图的一些常见刷新功能一样)。

假设有一个refreshToDo()函数, 我所需要的只是一个布局 (当我拖动它的主体时,它显示刷新标题,当标题处于特定高度时,它调用refreshToDo() ,当我释放它时,它返回顶部和隐藏),但如何实现呢? 谢谢

布局:(它包含主要内容和目标内容,您可以简单地ingore目标内容,它是用于全屏在webview中播放视频):

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <FrameLayout android:id="@+id/main_content" 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> <FrameLayout android:id="@+id/target_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black" android:visibility="gone" > </FrameLayout> </RelativeLayout>

分段:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.web_fragment, container, false); mTargetView = (FrameLayout) rootView.findViewById(R.id.target_view); mContentView = (FrameLayout) rootView.findViewById(R.id.main_content); mWebView = (WebView) rootView.findViewById(R.id.webView); mWebView.setVerticalScrollBarEnabled(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true); mWebView.setWebViewClient(new MyWebViewClient(getActivity())); mWebView.setWebChromeClient(new MyWebChromeClient(getActivity())); mWebView.getSettings().setDomStorageEnabled(true); mWebView.getSettings().setPluginState(WebSettings.PluginState.ON); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.addJavascriptInterface(this, "jsinterface"); // default go to video page mWebView.loadUrl("file://" + getActivity().getFilesDir().toString() + StorageUtils.finalfoldername.toString() + "video_list.html"); return rootView; }

如何添加自定义视图来实现下拉刷新? 谢谢

Currently I am working on a fragment that simply a webview with framelayout, the problem is, I would like to do something like the pull down refresh ( just like some refresh function common of list view ).

Assume there is a refreshToDo() function , all I need is just a layout (when I drag the body it show the refresh header, when the header at the certain height, it call refreshToDo() , when I release it , it go back to top and hide) , but how to implement that? thanks

layout: (It contains the main content and target content, you can simply ingore target content, it is for playing the video in fullscreen in webview):

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <FrameLayout android:id="@+id/main_content" 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> <FrameLayout android:id="@+id/target_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black" android:visibility="gone" > </FrameLayout> </RelativeLayout>

Fragment:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.web_fragment, container, false); mTargetView = (FrameLayout) rootView.findViewById(R.id.target_view); mContentView = (FrameLayout) rootView.findViewById(R.id.main_content); mWebView = (WebView) rootView.findViewById(R.id.webView); mWebView.setVerticalScrollBarEnabled(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true); mWebView.setWebViewClient(new MyWebViewClient(getActivity())); mWebView.setWebChromeClient(new MyWebChromeClient(getActivity())); mWebView.getSettings().setDomStorageEnabled(true); mWebView.getSettings().setPluginState(WebSettings.PluginState.ON); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.addJavascriptInterface(this, "jsinterface"); // default go to video page mWebView.loadUrl("file://" + getActivity().getFilesDir().toString() + StorageUtils.finalfoldername.toString() + "video_list.html"); return rootView; }

How to add the custom view to implement the pull down refresh? Thanks

最满意答案

查看令人敬畏的ActionBar-PullToRefresh库。 它使用gmail / google +进度条进行拉动以刷新手势,高度可配置,非常易于实施。

Check out the awesome ActionBar-PullToRefresh Library. It does the pull to refresh gesture using the gmail/ google+ progress bar, is highly configurable, very easy to implement.

更多推荐

本文发布于:2023-07-06 07:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047310.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   android   implement   pull   refresh

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!