2013-04-11 88 views
0

在Android中是否可以将WebView仅放在屏幕的一部分?如果是这样,那么XML是做什么的?如果可能的话,我想创建一个可滚动的HTML表格,因为它可能包含大量的数据行。感谢您的任何信息。WebView在屏幕的一部分(不是整个屏幕)

<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> 
+0

检查这个问题http://stackoverflow.com/questions/3382188/how-to-set-webview-as-non-fullscreen – Tiago 2013-04-11 16:50:28

+0

首先,你需要更具体的了解你正在尝试做的。屏幕的哪个部分需要“WebView”,以及多少?相对大小?静态大小?其次,你需要表现出一些努力,这不是一个代码商店... – 2013-04-11 16:51:15

+0

什么是你试过/得到代码? – petey 2013-04-11 16:52:14

回答

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" 
/> 
0

相反的RelativeLayout,你可以使用简单的LinearLayout。

<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> 
+0

有什么区别? – MasterGberry 2013-04-11 17:27:20

+0

区别在于这个布局包含按钮下方的WebView?这正是你要求的? – 2013-04-11 18:00:44