문제

I want to expand the webview1 view to fill the space remainning. make the button look like always on the bottom of Screen. I assign a weight to individual children with the android:layout_weight attribute. but It seems doesn't work. How can I do it ,can anybody tell me anything

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ScrollView style="@style/ScrollView" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:paddingBottom="8dp"
            android:paddingLeft="12dp"
            android:paddingRight="12dp"
            android:paddingTop="8dp" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_marginTop="12dp"
                android:orientation="vertical"
                android:layout_weight="1" >      <---here assign a weight

                <WebView
                    android:id="@+id/webview1"
                    **style="@style/update_text" />**
            </LinearLayout>

            <!-- h-line -->

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp" >

                <ImageView
                    android:id="@+id/line_end"
                    style="@style/form_h_line" />
            </RelativeLayout>

            <!-- buttons -->

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:orientation="horizontal" >

                <Space
                    android:layout_width="12dp"
                    android:layout_height="wrap_content"/>

                <Button
                    android:id="@+id/button_ok"
                    style="@style/base_button"
                    android:layout_width="12dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:text="OK"/>

                <Space
                    android:layout_width="12dp"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

</FrameLayout>

The reason is , because it works in Framelayout, so the webview1 can't expand automatically.

도움이 되었습니까?

해결책

fill_parent/match_parent does not work in a ScrollView for obvious reasons - if it did, the ScrollView would be useless.

Your ScrollView should have fillViewPort attribute set to true. This makes the ScrollView's child expand to height of the ScrollView if needed. If the child is larger than the screen, the attribute has no effect.

다른 팁

Add weightSum="" property to your LinearLayout

so use following and manage it as you want with wiegtSum and layout_weight also Use LinearLayout instead of <Space> tag

      <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:weightSum="3"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="1" 
                android:layout_height="wrap_content"/>

            <Button
                android:id="@+id/button_ok"
                style="@style/base_button"
                android:layout_width="12dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="OK"/>
           <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="1" 
                android:layout_height="wrap_content"/>

        </LinearLayout>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top