2013-01-03 154 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

只是固定的职位。 –