【发布时间】:2014-01-29 19:37:02
【问题描述】:
目前我正在研究一个片段,它只是一个带有框架布局的 webview,问题是,我想做一些类似 下拉刷新 的事情(就像列表视图的一些常见刷新功能) .
假设有一个refreshToDo()函数,我需要的只是一个布局(当我拖动正文时它显示刷新标题,当标题在一定高度时,它调用@987654324 @ ,当我释放它时,它会回到顶部并隐藏),但是如何实现呢?谢谢
layout:(它包含主要内容和目标内容,您可以简单地引入目标内容,用于在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;
}
如何添加自定义视图实现下拉刷新?谢谢
【问题讨论】:
标签: android android-layout android-fragments webview