WebView部分屏幕(不是整个屏幕)

时间:2013-04-11 16:47:46

标签: android android-webview

在Android中,是否可以只在屏幕的一部分放置WebView?如果是这样,XML是做什么的?我想创建一个带有HTML的表,如果可能的话,它是可滚动的,因为它可能包含很多行数据。感谢您的任何信息。

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/startButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="21dp"
        android:layout_marginTop="18dp"
        android:onClick="startDataGathering"
        android:text="Start" />

    <Button
        android:id="@+id/stopButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/startButton"
        android:layout_alignBottom="@+id/startButton"
        android:layout_alignParentRight="true"
        android:layout_marginRight="32dp"
        android:onClick="stopDataGathering"
        android:text="Stop" />

    <!-- want a webview here to cover rest of screen -->

</RelativeLayout>

2 个答案:

答案 0 :(得分:1)

可以像任何其他视图一样放置和显示WebView。从你的代码中,我猜你想要两个按钮下方的WebView,左上角是startButton,右上角是stopButton,两个按钮之间有间隙。

在你的情况下,由于两个按钮大概都是相同的高度,只需告诉WebView低于startButton,因为你的stopButton也是相对的:

<WebView
    android:id="@+id/web_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/startButton"
    android:layout_alignParentBottom="true"
/>

答案 1 :(得分:0)

您可以使用简单的LinearLayout而不是RelativeLayout。

<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:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/startButton"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="startDataGathering"
            android:text="Start" />

        <Button
            android:id="@+id/stopButton"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="stopDataGathering"
            android:text="Stop" />
    </LinearLayout>

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

</LinearLayout>
相关问题