使用RelativeLayout控制WebView以及Bottom按鈕的位置

來源:互聯網
上載者:User

標籤:

使用RelativeLayout控制WebView以及Bottom按鈕的位置 (地址)

在Design View中加入控制項RelativeLayout, WebView, LinearLayout(Horizontal), Button, Button。

  1. 添加新Layout - WebViewLayout.axml, 開啟檔案。 選中預設的LinearLayout並刪除。
  2. 添加RelativeLayout, 在Toolbox中拖動RelativeLayout控制項到頁面中。
  3. 拖動WebView控制項到RelativeLayout中。
  4. 拖動LinearLayout(Horizontal)到RelativeLayout中, 置於WebView之下。
  5. 拖動兩個Button到LinearLayout(Horizontal)中。

完成以上步驟以後,頁面原始碼如下:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"    p1:layout_width="match_parent"    p1:layout_height="match_parent"    p1:id="@+id/relativeLayout1">    <WebView        p1:layout_width="wrap_content"        p1:layout_height="wrap_content"        p1:id="@+id/webView1" />    <LinearLayout        p1:orientation="horizontal"        p1:minWidth="25px"        p1:minHeight="25px"        p1:layout_width="wrap_content"        p1:layout_height="wrap_content"        p1:layout_below="@id/webView1"        p1:id="@+id/linearLayout1">        <Button            p1:text="Button"            p1:layout_width="wrap_content"            p1:layout_height="match_parent"            p1:id="@+id/button2" />        <Button            p1:text="Button"            p1:layout_width="wrap_content"            p1:layout_height="match_parent"            p1:id="@+id/button1" />    </LinearLayout></RelativeLayout>

切換到Source View, 實現如下修改:

  1. 在WebView中,加入位置屬性。

    p1:layout_above="@+id/linearLayout1"
  2. 修改WebView的layout_width, layout_height屬性為fill_parent。

    p1:layout_width="fill_parent"p1:layout_height="fill_parent"
  3. 添加LinearLayout的layout_alignParentBottom屬性。

    p1:layout_alignParentBottom="true"
  4. 修改LinearLayout的layout_width, layout_height屬性。

    p1:layout_width="match_parent"p1:layout_height="wrap_content"
  5. 為了使兩個Button平分空間, 加入layout_weight屬性。

    p1:layout_weight="0.5"

修改後的原始碼如下:

  <?xml version="1.0" encoding="utf-8"?>  <RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"      p1:layout_width="match_parent"      p1:layout_height="match_parent"      p1:id="@+id/relativeLayout1">      <WebView          p1:layout_width="fill_parent"          p1:layout_height="fill_parent"          p1:id="@+id/webView1"          p1:layout_above="@+id/linearLayout1" />      <LinearLayout          p1:orientation="horizontal"          p1:minWidth="25px"          p1:minHeight="25px"          p1:layout_width="match_parent"          p1:layout_height="wrap_content"          p1:layout_below="@id/webView1"          p1:id="@+id/linearLayout1"          p1:layout_alignParentBottom="true">          <Button              p1:text="Button"              p1:layout_width="wrap_content"              p1:layout_height="match_parent"              p1:id="@+id/button2"              p1:layout_weight="0.5" />          <Button              p1:text="Button"              p1:layout_width="wrap_content"              p1:layout_height="match_parent"              p1:id="@+id/button1"              p1:layout_weight="0.5" />      </LinearLayout>  </RelativeLayout>

 

使用RelativeLayout控制WebView以及Bottom按鈕的位置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.