2013-04-11 152 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