0

我需要为 android 创建一个基本浏览器:一个 WebView 顶部的工具栏带有后退按钮,底部的工具栏带有更多按钮。

这样做的最佳方法是什么?

这是我到目前为止所拥有的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

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

    <WebView
        android:id="@+id/webView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/backButton"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:src="@drawable/back" />

        <ImageButton
            android:id="@+id/forwardButton"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:src="@drawable/forward" />

        <ImageButton
            android:id="@+id/reloadButton"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:src="@drawable/reload" />

        <ImageButton
            android:id="@+id/browserButton"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:src="@drawable/safari" />
    </LinearLayout>

</LinearLayout>

按钮的底部 LinearLayout 根本不显示。只有顶部的后退按钮和 WebView。

4

2 回答 2

1

线性布局没问题。

您应该更改控件​​的高度WebView并将权重设置为 1

这样做:

<WebView android:layout_height="fill_parent" android:layout_weight="1" android:layout_width="fill_parent"

甚至如此,正如 Lint 工具所推荐的那样:

<WebView android:layout_height="0dip" android:layout_weight="1" android:layout_width="fill_parent"

权重很重要,它强制视图填充剩余空间。

如果还是不行,你也可以尝试将底部面板的高度设置为某个常数值,或者将图片按钮的高度设置为wrap_content,那么你可以确定它会起作用。

于 2012-08-20T19:57:31.113 回答
0

就个人而言,我不喜欢嵌套LinearLayouts,当您的布局变得更复杂时,它会影响性能。对于小事来说可能没什么大不了的。但是,使用RelativeLayouts.

xmlns:android="http://schemas.android.com/apk/res/android"此外,在你的第二个中失去LinearLayout。你不需要它。

希望这可以帮助。

于 2012-08-20T19:37:09.227 回答