Nom*_*man 6 android scrollview webview
我有什么:
现在我有一个Scroll视图作为父母.在这个滚动视图中,我使用的是一个加载URL然后在其中显示文本的WebView.这是我的xml:
<ScrollView
android:id="@+id/parentScroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Heading" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp" >
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@drawable/webview" />
</RelativeLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
我想要的是:
我想在其中滚动webView.当我触摸webView时,很遗憾地会调用父滚动视图.我还要保留父滚动视图,但除此之外,我想在我触摸webView时滚动其中的WebView内容.
我怎样才能做到这一点?
创建自定义触摸拦截Webview
CustomWebview.java
package com.mypackage.common.custom.android.widgets
public class CustomWebview extends WebView {
public CustomWebview(Context context) {
super(context);
}
public CustomWebview(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomWebview(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onTouchEvent(MotionEvent event){
requestDisallowInterceptTouchEvent(true);
return super.onTouchEvent(event);
}
}
Run Code Online (Sandbox Code Playgroud)
在layout.xml中
<com.package.custom.widgets.CustomWebview
android:id="@+id/view_extra"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Run Code Online (Sandbox Code Playgroud)
根据 Android 设计文档,如果滚动容器的滚动方向相同,则永远不应该将滚动容器放入滚动容器内。它不是为了处理这样的事情。
| 归档时间: |
|
| 查看次数: |
13406 次 |
| 最近记录: |