在scrollview中启用webview缩放控件

时间:2016-05-18 03:51:51

标签: android webview

我在webview内有一个Scrollview。点击webview时我需要进行缩放控制,但显然当父布局为scrollview时它不起作用。解决办法是什么?有没有办法在这种情况下进行变焦控制?

这是我的xml代码:

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/container_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:visibility="gone">

            <include
                android:id="@+id/toolbar"
                layout="@layout/toolbar" />
        </LinearLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFF">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FFF"
            android:orientation="vertical">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="380dp">

                <LinearLayout
                    android:id="@+id/linearLayout1"
                    android:layout_width="match_parent"
                    android:layout_height="300dp"
                    android:background="@color/item_bg"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/tv_title_news"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center"
                        android:paddingBottom="20dp"
                        android:paddingLeft="5dp"
                        android:paddingRight="5dp"
                        android:paddingTop="20dp"
                        android:shadowColor="#000"
                        android:shadowDx="1"
                        android:shadowDy="3"
                        android:shadowRadius="5"
                        android:text="Medium"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textColor="#FFF" />
                </LinearLayout>

                <ImageView
                    android:id="@+id/img_news_pic"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:visibility="gone" />


                <ir.whc.news.views.CircularNetworkImageView
                    android:id="@+id/img_circleThumbnail1"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_marginBottom="33dp"
                    android:layout_marginLeft="10dp">

                </ir.whc.news.views.CircularNetworkImageView>

                <TextView
                    android:id="@+id/tv_cnt_eye"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/linearLayout1"
                    android:layout_marginBottom="10dp"
                    android:layout_marginTop="5dp"
                    android:layout_toRightOf="@+id/fontAwesomeText1"
                    android:paddingLeft="6dp"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="#FFF"
                    android:textSize="11dp" />

                <com.beardedhen.androidbootstrap.AwesomeTextView
                    android:id="@+id/fontAwesomeText1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/linearLayout1"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="16dp"
                    android:layout_toRightOf="@+id/img_circleThumbnail1"
                    android:textColor="#FFF"

                    app:fontAwesomeIcon="fa_eye"
                    />
                <com.beardedhen.androidbootstrap.AwesomeTextView
                    android:id="@+id/fontAwesomeText2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/fontAwesomeText1"
                    android:layout_marginLeft="16dp"
                    android:layout_marginTop="10dp"
                    android:layout_toRightOf="@+id/img_circleThumbnail1"
                    android:textColor="#000"
                    app:fontAwesomeIcon="fa_clock_o" />

                <TextView
                    android:id="@+id/tv_date"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/fontAwesomeText1"
                    android:layout_marginTop="10dp"
                    android:layout_toRightOf="@+id/fontAwesomeText2"
                    android:paddingLeft="6dp"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="#000"
                    android:textSize="13dp" />


            </RelativeLayout>

            <TextView
                android:id="@+id/tv_sum_news"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:lineSpacingExtra="15dp"
                android:paddingBottom="20dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/tv_desc_news"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:visibility="gone" />

            <WebView
                android:scrollbars="vertical"
                android:clickable="true"
                android:id="@+id/webView1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:textAlignment="center"
                android:textDirection="rtl" />
        </LinearLayout>
    </ScrollView>
    <LinearLayout

        android:background="@drawable/grad"
        android:layout_alignParentTop="true"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="right">
        <ImageView
            android:id="@+id/image_bookmark_content"
            android:layout_width="@dimen/bookmerk_content_size"
            android:layout_height="@dimen/bookmerk_content_size"
            android:src="@drawable/ic_bookmark_normal"/>
        <ImageView
            android:id="@+id/image_share_content"
            android:layout_width="@dimen/bookmerk_content_size"
            android:layout_height="@dimen/bookmerk_content_size"
            android:src="@drawable/ic_share"/>

    </LinearLayout>
</RelativeLayout>


    </LinearLayout>


    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="ir.whc.news.activity.FragmentDrawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer" />

</android.support.v4.widget.DrawerLayout>

1 个答案:

答案 0 :(得分:2)

使用,

 webView.getSettings().setBuiltInZoomControls(true);
 webView.getSettings().setDisplayZoomControls(false);

  

检查您是否没有 ScrollView包装您的Webview

就我而言,这就是问题所在。似乎ScrollView妨碍了捏合手势。

要修复它,只需将您的Webview放在ScrollView外面。