如何在线性布局中使用webview和相对布局

时间:2011-05-02 10:00:53

标签: android android-layout-weight

我有一个线性布局,在里面我有一个webview和一个相对布局。我希望webview占用所有可用空间,让相对布局保持高度包含在内容上。

我尝试了多种方法,但我仍然无法使其正常工作。

有人可以向我解释如何让webview占用所有可用空间,并将我的相对布局保持在底部,并将其内容包裹起来。

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

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:background="@drawable/titlebar_top">

    <ImageView android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:background="@drawable/logo"
        android:layout_centerHorizontal="true" android:layout_centerVertical="true">
    </ImageView>

    <ImageButton android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:background="@drawable/redarrowright"
        android:layout_alignParentRight="true" android:layout_centerVertical="true"
        android:id="@+id/imgArticlePrevious" android:layout_marginRight="10dip">
    </ImageButton>

    <ImageButton android:id="@+id/imgArticleRight"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:background="@drawable/redarrowleft"
        android:layout_centerVertical="true" android:layout_toLeftOf="@+id/imgArticlePrevious"
        android:layout_marginRight="10dip">
    </ImageButton>
</RelativeLayout>

<TextView
        android:id= "@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Le soleisl sssssssssssssssss"
        android:layout_gravity="center_horizontal"
        android:textSize="22sp"
        android:gravity="center"
        android:textStyle="bold"
        android:maxLines="2">
</TextView>

<LinearLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/txtCategory" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Info"
        android:textColor="@color/red">
    </TextView>
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="|">
    </TextView>
    <TextView android:id="@+id/txtDate" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="26/03/2011"
        android:textColor="@color/gray">
    </TextView>
</LinearLayout>


<WebView android:id="@+id/webview" android:layout_width="fill_parent"
    android:layout_height="fill_parent" layout_weight="90" />

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/articlebanner"
    android:layout_gravity="bottom"
    android:layout_weight="10">

    <ImageButton android:id="@+id/imgComment"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:background="@drawable/commenticon"
        android:layout_centerVertical="true">
    </ImageButton>

    <Button android:id="@+id/txtCommentCount"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:background="@drawable/commentbackground"
        android:layout_marginLeft="10dip" android:text="4" android:textColor="@color/white"
        android:textStyle="bold" android:layout_alignTop="@+id/imgComment">
    </Button>

    <Button android:id="@+id/imgShare" android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:background="@drawable/buttonshare"
        android:layout_alignParentRight="true" android:layout_centerVertical="true"
        android:layout_marginRight="2dip" android:drawableLeft="@drawable/sharebtnicon"
        android:drawablePadding="2dip" android:text="Partagez"
        android:textColor="@color/white" android:textStyle="bold">
    </Button>
</RelativeLayout>

Webview - 占用位于顶部和底部的其他小部件之间的所有剩余空间

1 个答案:

答案 0 :(得分:1)

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

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:background="@drawable/titlebar_top">

    <ImageView android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:background="@drawable/logo"
        android:layout_centerHorizontal="true" android:layout_centerVertical="true">
    </ImageView>

    <ImageButton android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:background="@drawable/redarrowright"
        android:layout_alignParentRight="true" android:layout_centerVertical="true"
        android:id="@+id/imgArticlePrevious" android:layout_marginRight="10dip">
    </ImageButton>

    <ImageButton android:id="@+id/imgArticleRight"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:background="@drawable/redarrowleft"
        android:layout_centerVertical="true" android:layout_toLeftOf="@+id/imgArticlePrevious"
        android:layout_marginRight="10dip">
    </ImageButton>
</RelativeLayout>

<TextView
        android:id= "@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:layout_gravity="center_horizontal"
        android:textSize="22sp"
        android:gravity="center"
        android:textStyle="bold"
        android:maxLines="2">
</TextView>

<LinearLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/txtCategory" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Info"
        android:textColor="@color/red">
    </TextView>
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="|">
    </TextView>
    <TextView android:id="@+id/txtDate" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="26/03/2011"
        android:textColor="@color/gray">
    </TextView>
</LinearLayout>

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<WebView android:id="@+id/webview" android:layout_width="fill_parent"
    android:layout_height="fill_parent" layout_weight="1"
    android:layout_above="@+id/sharebar" />

<RelativeLayout
    android:id="@+id/sharebar"
     android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:background="@drawable/articlebanner"
    android:layout_gravity="bottom" android:layout_alignParentBottom="true">

    <ImageButton android:id="@+id/imgComment"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:background="@drawable/commenticon"
        android:layout_centerVertical="true">
    </ImageButton>

    <Button android:id="@+id/txtCommentCount"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:background="@drawable/commentbackground"
        android:layout_marginLeft="10dip" android:text="4" android:textColor="@color/white"
        android:textStyle="bold" android:layout_alignTop="@+id/imgComment">
    </Button>

    <Button android:id="@+id/imgShare" android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:background="@drawable/buttonshare"
        android:layout_alignParentRight="true" android:layout_centerVertical="true"
        android:layout_marginRight="2dip" android:drawableLeft="@drawable/sharebtnicon"
        android:drawablePadding="2dip" android:text="Partagez"
        android:textColor="@color/white" android:textStyle="bold">
    </Button>
</RelativeLayout>

</RelativeLayout>

解决了,我把它放在另一个相对布局中,对齐底部的栏并在其上方设置webview。工作:)