我正在努力弄清楚如何使这个简单的布局工作。我想要一个中心按钮行上的webview。如果我指定一个特定的dp,比如400dp,我可以看到顶部的webview和屏幕底部的按钮。但是,对于多种屏幕尺寸,这不能很好地扩展。如果我使用“fill_parent”,那么我从来没有看到webview下面的按钮。Android WebView下面有一排按钮
我只是想要一个布局,将始终将按钮放在屏幕的底部(而不是滚动屏幕),并让webview占据上面的空间的其余部分。我使用的是相对布局,因为我想在webview加载时在屏幕上居中显示进度指示器。
这里是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ProgressBar android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="@android:style/Widget.ProgressBar.Inverse"
/>
<WebView android:layout_width="fill_parent"
android:id="@+id/webview"
android:layout_alignParentTop="true"
android:layout_height="400dp"
android:layout_weight="1">
</WebView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/webview"
>
<Button android:text="Browse"
android:id="@+id/btnBrowse"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:drawableTop="@drawable/brouse"
android:textSize="9dp"
/>
<Button android:text="Account"
android:id="@+id/btnAccount"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:drawableTop="@drawable/account"
android:layout_toRightOf="@+id/btnBrowse"
android:textSize="9dp"
/>
<Button android:text="Contact"
android:id="@+id/btnContact"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1.0"
android:drawableTop="@drawable/contact"
android:layout_toRightOf="@+id/btnAccount"
android:textSize="9dp"
/>
<Button android:text="Quote"
android:id="@+id/btnQuote"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:drawableTop="@drawable/custom"
android:layout_toRightOf="@+id/btnContact"
android:textSize="9dp"
/>
</LinearLayout>
</RelativeLayout>
UPDATE:
我尝试了一些更多的试验,得到了几乎我想要的东西,除了按钮在屏幕的顶部出于某种原因! WTF?无论如何,我会尽快尝试一些你们的建议!谢谢!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ProgressBar android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="@android:style/Widget.ProgressBar.Inverse"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="9.0"
android:layout_alignParentTop="true">
</WebView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"
android:layout_alignParentBottom="true"
>
<Button android:text="Browse"
android:id="@+id/btnBrowse"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:drawableTop="@drawable/brouse"
android:textSize="9dp"
/>
<Button android:text="Account"
android:id="@+id/btnAccount"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:drawableTop="@drawable/account"
android:textSize="9dp"
/>
<Button android:text="Contact"
android:id="@+id/btnContact"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1.0"
android:drawableTop="@drawable/contact"
android:textSize="9dp"
/>
<Button android:text="Quote"
android:id="@+id/btnQuote"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:drawableTop="@drawable/custom"
android:textSize="9dp"
/>
</LinearLayout>
</LinearLayout>
小错字找到,第3行:它必须是android:layout_above =“@ + id/buttons”(加号缺少) – eav 2015-10-21 14:08:12