Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webview inside a View pager in android

I have a WebView at the bottom of view in ViewPager... When I slide through the items of ViewPager. The View moves on down. (I guess the focus goes to webview) I am not sure whether this is due to WebView. Loading the webview with html data using webView.loadDataWithBaseURL(null, data, "text/html","utf-8",null);

It's annoying when the page moves down every time the next item is loaded. I have an ImageView at the top of the View

Any pointers?

here is the xml:

<ScrollView
        android:id="@+id/scroll_view_1"
        style="@style/some_style"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fadingEdge="none" >

        <LinearLayout
            android:id="@+id/linear_layout_1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/some_drawable"
            android:orientation="vertical" >

            <RelativeLayout
                android:id="@+id/relative_layout_1"
                android:layout_width="fill_parent"
                android:layout_height="250dp"
                android:paddingLeft="5dip"
                android:paddingRight="5dip" >

                <LinearLayout
                    android:id="@+id/linear_layout_2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_marginTop="5dip"
                    android:gravity="center" >

                    <PageIndicator
                        android:id="@+id/page_indicator"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:padding="10dip" />
                </LinearLayout>

                <RelativeLayout
                    android:id="@+id/relative_layout_2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="true"
                    android:visibility="visible" >

                    <TextView
                        android:id="@+id/text_view_1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_marginRight="10dip"
                        android:text="1/50"
                        android:textColor="#000000"
                        android:textSize="16sp" />

                    <ImageView
                        android:id="@+id/image_view_1"
                        android:layout_width="35dip"
                        android:layout_height="35dip"
                        android:layout_marginRight="5dip"
                        android:layout_toLeftOf="@id/text_view_1"
                        android:scaleType="centerInside"
                        android:src="@drawable/some_drawable_3" />

                    <ImageView
                        android:id="@+id/image_view_2"
                        android:layout_width="35dip"
                        android:layout_height="35dip"
                        android:layout_marginRight="5dip"
                        android:layout_toLeftOf="@id/image_view_1"
                        android:scaleType="centerInside"
                        android:src="@drawable/some_drawable_4" />
                </RelativeLayout>
            </RelativeLayout>

            <RelativeLayout
                android:layout_width="relative_layout_3"
                android:layout_height="wrap_content"
                android:background="#f8f8f8"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="5dip"
                android:paddingTop="5dip" >

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:gravity="center_vertical" >

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:scaleType="centerInside"
                        android:src="@drawable/some_drawbale_2" />

                    <TextView
                        android:id="@+id/text_view_2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginLeft="6dip"
                        android:gravity="left|center_vertical"
                        android:paddingLeft="3dip"
                        android:paddingRight="7dip"
                        android:text="$121.00"
                        android:textColor="#000000"
                        android:textSize="16sp"
                        android:textStyle="bold" />

                    <Button
                        android:id="@+id/button_1"
                        android:layout_width="95dip"
                        android:layout_height="30dip"
                        android:layout_gravity="center_vertical"
                        android:layout_marginLeft="15sp"
                        android:background="@drawable/some_drawable_5"
                        android:gravity="center"
                        android:textSize="15dip" />
                </LinearLayout>
            </RelativeLayout>

            <TextView
                android:id="@+id/text_view_3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dip"
                android:layout_marginRight="10dip"
                android:layout_marginTop="10dip"
                android:gravity="left"
                android:lineSpacingExtra="2dip"
                android:text="Some Text"
                android:textColor="#000000"
                android:textSize="16sp"
                android:textStyle="bold" />

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingBottom="10dip"
                android:paddingTop="15dip" >

                <WebView
                    android:id="@+id/web_view"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dip"
                    android:layout_marginRight="10dip"
                    android:focusable="false"/>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
like image 551
fahms Avatar asked Jun 13 '12 06:06

fahms


1 Answers

I had the same kind of issue. And adding this attribute to the top most linear layout solved the issue. try this,

  android:descendantFocusability="blocksDescendants". 

In your case add this to your Linear Layout inside the ScrollView and check.

like image 113
Andro Selva Avatar answered Oct 04 '22 03:10

Andro Selva