2011-05-02 186 views
0

我有一個線性佈局,裏面,我有一個webview和相對佈局。我想讓webview佔據所有可用空間,並讓相對佈局保持其內容上的高度。佈局android重量問題

我嘗試了多種方法,但仍然無法正常工作。

有人可以向我解釋我怎麼能讓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> 

網頁視圖 - 位於上方的其他部件和底部

+0

你可以發佈一些你的嘗試示例代碼? – Matthias 2011-05-02 10:03:41

+0

有代碼。 – Hades 2011-05-02 10:08:31

+1

'android:layout_width =「fill_parent」android:layout_height =「fill_parent」layout_weight =「90」'< - 這沒有意義。您必須根據重量將軸想要增大或縮小爲0px。 – Matthias 2011-05-02 11:27:33

回答

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> 
0之間佔用的所有空間的剩餘空間

解決了,我把它放在另一個相對佈局中,將底部的條對齊,並在上面設置webview。工作:)

0

嘗試使用單獨的佈局,爲您的網頁視圖