其实实现起来,也是相当的简单,这和scrollview嵌套listview是完全类似的原因和操作,包括现象都一样啊,那么就撸代码:
/** * @author jakezhang * @date 2016年4月26日 */ public class NoScrollWebView extends WebView { @SuppressLint("NewApi") public NoScrollWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public NoScrollWebView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public NoScrollWebView(Context context, AttributeSet attrs) { super(context, attrs); } public NoScrollWebView(Context context) { super(context); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int mExpandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, mExpandSpec); } }xml中:
<ScrollView android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <com.freedev.tool.view.NoScrollWebView android:id="@+id/webViewNet" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" /> </LinearLayout> </ScrollView>在activity中:
webView.loadData(url, "text/html; charset=UTF-8", "UTF-8");这样一来,就可以了,scrollview中可以嵌套webview,也可以加入其它的东西一起在这个scrollview中滑动了。
