標籤:
使用RelativeLayout控制WebView以及Bottom按鈕的位置 (地址)
在Design View中加入控制項RelativeLayout, WebView, LinearLayout(Horizontal), Button, Button。
- 添加新Layout -
WebViewLayout.axml, 開啟檔案。 選中預設的LinearLayout並刪除。
- 添加RelativeLayout, 在Toolbox中拖動RelativeLayout控制項到頁面中。
- 拖動WebView控制項到RelativeLayout中。
- 拖動LinearLayout(Horizontal)到RelativeLayout中, 置於WebView之下。
- 拖動兩個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, 實現如下修改:
-
在WebView中,加入位置屬性。
p1:layout_above="@+id/linearLayout1"
-
修改WebView的layout_width, layout_height屬性為fill_parent。
p1:layout_width="fill_parent"p1:layout_height="fill_parent"
-
添加LinearLayout的layout_alignParentBottom屬性。
p1:layout_alignParentBottom="true"
-
修改LinearLayout的layout_width, layout_height屬性。
p1:layout_width="match_parent"p1:layout_height="wrap_content"
-
為了使兩個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按鈕的位置