目前我正在开发一个片段,它只是一个带有框架布局的网络视图,问题是,我想做类似的事情下拉刷新(就像列表视图中常见的一些刷新功能一样)。
假设有一个refreshToDo()
功能 ,我所需要的只是一个布局(当我拖动主体时,它会显示刷新标题,当标题达到一定高度时,它会调用refreshToDo()
,当我释放它时,它会返回顶部并隐藏),但是如何实现呢?谢谢
布局:(包含主要内容和目标内容,可以忽略目标内容,用于在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;
}
如何添加自定义View实现下拉刷新?谢谢
现在Android支持库中有一个官方的小部件SwipeRefreshLayout。它正在做您正在寻找的事情。文档在这里:
https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
这是我发现的一个很好的教程:
http://antonioleiva.com/swiperefreshlayout/ http://antonioleiva.com/swiperefreshlayout/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)