1

I have a WebView inside a scrollview and I want to make the scrolling inside the webview more experienced for the user- When you start scrolling horizontally> I want to turn off vertical scrolling. and the opposite. I tried this solution: https://stackoverflow.com/a/24734588 But it completely disabling the vertical scrolling of the webview so I can`t scroll up or down.

My code:

package com.tachles;

import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.ListView;

public class History_04_01 extends TextSet {

    WebView myweb;
    LinearLayout ll1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String formattedText = getString(R.string.buildcountry01);
        ll1 = (LinearLayout) findViewById(R.id.linear2);
        Spanned result = Html.fromHtml(formattedText);
        text.setText(result);

        myweb = new WebView(this);
        myweb.loadUrl("file:///android_asset/tavla.png");
        ll1.addView(myweb);

        // your HorizontalScrollView inside scrollview
        myweb.setOnTouchListener(new ListView.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                switch (action) {
                case MotionEvent.ACTION_DOWN:
                    // Disallow ScrollView to intercept touch events.
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    break;

                case MotionEvent.ACTION_UP:
                    // Allow ScrollView to intercept touch events.
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
                }

                // Handle HorizontalScrollView touch events.
                v.onTouchEvent(event);
                return true;
            }
        });

    }

    public void sizeUp(MenuItem item) {

        super.sizeUp(item);
    }

    public void sizeDown(MenuItem item) {

        super.sizeDown(item);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.textbar, menu);
        return true;
    }

    @Override
    protected void onStart() {
        super.onStart();

    }

    @Override
    protected void onStop() {
        super.onStop();

    }
}

and the XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relative1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" >

        <RelativeLayout
            android:id="@+id/linear1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:gravity="right" />

            <LinearLayout
                android:id="@+id/linear2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/textView1"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:orientation="vertical" >
            </LinearLayout>
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>
Community
  • 1
  • 1
Max
  • 319
  • 1
  • 4
  • 18

0 Answers0