2013-01-03 156 views
0

這是我的XML代碼(我遵循了這一post,但它不工作):按鈕沒有顯示

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<WebView 
    android:id="@+id/webChapter" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true"/> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:layout_below="@+id/webChapter" 
    android:layout_alignParentBottom="true"> 

    <Button 
     android:id="@+id/btnMenu" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Back To Menu" /> 

    <Button 
     android:id="@+id/btnNavi" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Example" /> 

    <Button 
     android:id="@+id/btnQuestion" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Quiz" /> 
</LinearLayout> 

這是圖形之一:

enter image description here

當我的webview變得太高時,我的按鈕不顯示。我該怎麼辦?謝謝:D

回答

2

嘗試以下操作:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<WebView 
    android:id="@+id/webChapter" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_above="@+id/linearlayout"/> 

<LinearLayout 
    android:id="@+id/linearlayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:layout_alignParentBottom="true"> 

    <Button 
     android:id="@+id/btnMenu" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Back To Menu" /> 

    <Button 
     android:id="@+id/btnNavi" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Example" /> 

    <Button 
     android:id="@+id/btnQuestion" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Quiz" /> 
</LinearLayout> 

希望這將幫助你

+0

謝謝:d 但是,什麼是不同的採用了android的:layout_below = 「webviewid」 和android:layout_above = 「linearid」?爲什麼第一個不工作,但第二個工作? –

+1

@BlazeTama通過設置android:layout_below =「webviewid」,您可以指定您的佈局位於您的webview下方,但是如果您的webview太大,您的佈局將不在屏幕上。通過設置android:layout_above =「linearid」,您可以指示您的webview位於佈局之上。我知道一開始我很難理解(我記得:p),但我唯一可以做的建議是不斷練習,它會讓你更清楚。另一種方式是用垂直線性替換你的relativelayout,使你的webview 0dp高度和1weight,以及wrap_content線性化。 – AMerle

+0

感謝您的解釋,是的它有點難,但你的解釋讓我更好地理解:D –

1

嘗試下面的佈局,希望它適合你。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="10" > 

    <WebView 
     android:id="@+id/webChapter" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="9" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:gravity="center_horizontal" > 

     <Button 
      android:id="@+id/btnMenu" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Back To Menu" /> 

     <Button 
      android:id="@+id/btnNavi" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Example" /> 

     <Button 
      android:id="@+id/btnQuestion" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Quiz" /> 
    </LinearLayout> 
</LinearLayout> 

上面的代碼將沿着webview有按鈕。如果您可以使用webview上方的按鈕,那麼也不需要使用權重。你可以把webview放在按鈕佈局的下面。

+0

感謝您的答案:d –

1

喜試試這個下面的一個

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<WebView 
    android:id="@+id/webChapter" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_alignBottom="@+id/btnLayout"/> 

<LinearLayout 
    android:id="@+id/btnLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:layout_below="@+id/webChapter"> 

    <Button 
     android:id="@+id/btnMenu" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Back To Menu" /> 

    <Button 
     android:id="@+id/btnNavi" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Example" /> 

    <Button 
     android:id="@+id/btnQuestion" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Quiz" /> 
</LinearLayout> 
+0

感謝您的幫助:D –

1

你可以確定一個高度的網頁視圖,或者可能定義一個id到您的LinearLayout並在您的webView上設置屬性android:layout_above,以確保您的webview將在按鈕上方不浮動。

嘗試是這樣的:

<WebView 
    android:id="@+id/webChapter" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/lowerBar" 
    android:layout_alignParentTop="true"/> 

<LinearLayout 
    android:id="@+id/lowerBar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:layout_alignParentBottom="true"> 
+1

感謝:D 但你的答案使我的應用程序的力量關閉。它是因爲android:layout_below =「@ + id/webChapter」。 其循環依賴關係:D –

+1

哎呀,只是刪除下面的部分 –

+1

只是固定的職位。 –