开发者

problem with height in WebView

开发者 https://www.devze.com 2023-01-22 05:30 出处:网络
I have the next xml layout file: <ViewFlipper android:id=\"@+id/details\" android:layout_width=\"fill_parent\"

I have the next xml layout file:

<ViewFlipper android:id="@+id/details"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <!-- ListView que define la lista de noticias -->
    <ListView
        android:id="@+id/list"
        android:cacheColorHint="@android:color/transparent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

    <!-- Layout del detalle de una noticia -->
    <ScrollView
      android:id="@+id/scroll"  
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="#FFFFFFFF">

        <LinearLayout 
         android:id="@+id/widget"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:orientation="vertical">

            <RelativeLayout android:id="@+id/top"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="2dip"
                android:background="@drawable/header">
                <Button android:id="@+id/back" 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                    android:layout_marginTop="5.0dip"
                    android:layout_marginLeft="5.0dip"
                    android:padding="5.0dip"
                    android:background="@drawable/custom_buttom"
                    android:text="Atrás" 
                    android:textStyle="bold"
                    android:textSize="11.0dip"
                    android:textColor="#FFFFFF"/>

                <Button android:id="@+id/share"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5.0dip"
                    android:layout_marginRight="5.0dip"
                    android:padding="5.0dip"
                    android:background="@drawable/custom_buttom"
                    android:text="Compartir" 
                    android:textStyle="bold"
                    android:textColor="#FFFFFF"
                    android:textSize="11.0dip"
                    android:layout_alignParentRight="true">
                </Button>
            </RelativeLayout>

            <TextView
              android:id="@+id/title"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_marginTop="12dip"
              android:padding="10dip"
              android:gravity="fill_horizontal"
              android:textStyle="bold"
              android:textSize="22dip"
              android:textColor="#000000"/>

            <TextView
              android:id="@+id/date"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:paddingLeft="10dip"
              android:gravity="left"
              android:textSize="11dip"
              android:textColor="#000000"/>

            <WebView
             android:id="@+id/message"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:layout_marginTop="12dip"
             android:padding="10dip"
             android:gravity="fill_horizontal"
             android:textSize="14dip"
             android:layout_centerInParent="true"/>

            <TextView
              android:id="@+id/source"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:paddingLeft="10dip"
            开发者_高级运维  android:gravity="center"
              android:textSize="11dip"
              android:textColor="#000000"/>
        </LinearLayout>
    </ScrollView>
</ViewFlipper>

where the content in the WebView is dinamically changed depending the item selected in a previous ListView (the first view in the ViewFlipper).

The problem is when I set a new content in the WebView after the view has been filled with text. If the first text set is longer than the next one, the second time I have a large blank space between the finish of the WebView text and the footer I have in the screen. Do anyone know what is the problem ?

Another problem I have is with de focus. The first time I load this view it is focused in the top, but the second one is focused directlly in the WebView.


I had similar problem. Solved this by using FrameLayout.

Looks like this in the function for page switching for me:

FrameLayout frame = (FrameLayout) findViewById(R.id.frame);
frame.removeAllViews();

WebView webView = new WebView(yourContext); 

// do whatever you need to do with webView

frame.addView(webView);


In your WebView try replacing
android:layout_height="fill_parent"
with
android:layout_height="wrap_content"

0

精彩评论

暂无评论...
验证码 换一张
取 消