[英]Android: Prevent Only Vertical Scrolling in WebView
這是我的代碼-
// disable scroll on touch
webview.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return (event.getAction() == MotionEvent.ACTION_MOVE);
}
});
但是問題在於它禁用了所有滾動(水平和垂直滾動)。 有什么方法可以禁用垂直滾動並保持水平滾動嗎?
您可以使用WebView
的內置方法來禁用水平滾動 ,這比操作WebView的OnTouchListener
容易
解:
webview.setHorizontalScrollBarEnabled(false);
編輯:
將其包裝在水平滾動視圖中
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView
android:id="@+id/mywebview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</HorizontalScrollView>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.