我的佈局文件定義了一個WebView,在其下面有一些固定高度的按鈕。如何在WebView中添加填充
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1.0"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
android:padding="8dp">
<Button
android:text="Decline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0">
</Button>
<Button
android:text="Accept"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0">
</Button>
</LinearLayout>
</LinearLayout>
我嘗試添加填充周圍的WebView,因爲此刻的文本運行一直到UI的邊緣。
我試着將android:padding="8dp"
添加到WebView中,但沒有添加填充。我也嘗試了paddingLeft和paddingRight,但他們也沒有工作。
WebView API文檔確認它繼承自View,它支持android:padding屬性,所以我很驚訝這沒有奏效。
有沒有人知道這是一個已知的問題,還是我不明白的佈局XML的一些相互作用?
僅供參考,我的解決方法是把一個額外的LinearLayout各地的WebView,並填充添加到代替:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1.0"
android:padding="8dp">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
嘗試利潤而不是填充 - 我認爲這就是你想要的。填充對於WebView imo不是真的有意義 – AJcodez 2012-02-07 02:12:35
好主意,但是我只是嘗試在原始XML中的WebView上設置layout_marginRight和layout_marginLeft,並導致下面的按鈕未顯示。我不知道爲什麼我的佈局有什麼根本性的錯誤? – 2012-02-07 02:47:33
看起來你的layout_weight設置不正確。爲什麼給按鈕layout_weight,如果他們是wrap_content? – AJcodez 2012-02-07 17:51:19