簡體   English   中英

兩個按鈕和它們之間的webView

[英]Two buttons and webView between them

如何在布局中添加兩個按鈕(頂部和底部)以及它們之間的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" >

    <Button
        android:id="@+id/first"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="First" />

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:layout_below="@+id/first"
        android:layout_centerHorizontal="true" />

    <Button
        android:id="@+id/last"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/webView"
        android:text="Last" />

</RelativeLayout> 

但這僅向我顯示了第一個按鈕和WebView。 也許高度比350dp更好?

我該怎么做?

使用權重嘗試一下; 始終避免在視圖中設置物理值。

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

   <Button
      android:id="@+id/first"
      android:layout_width="fill_parent"
      android:layout_height="0dp"
      android:layout_weight="0.2"
      android:text="First" />

   <WebView
      android:id="@+id/webView"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="0.6"
      android:layout_gravity="center_horizontal />

  <Button
      android:id="@+id/last"
      android:layout_width="fill_parent"
      android:layout_height="0dp"
      android:layout_weight="0.2"
      android:text="Last" />

</LinearLayout>

那會做你想要的; 例如,將button1放在頂部,將button2放在底部,將Web視圖放在中間; 權重有助於相應地共享屏幕,而無需對高度等值進行硬編碼。

我希望這有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM