如何制作webview是-10dp父布局的宽度和高度,背景图像如下图所示:
更新: 蓝框是屏幕。 黑框是外部布局(@ + id / wrapper),红框是webview(@ + id / webview) 绿色框是其他布局。
我尝试使用以下代码但没有成功。 如果webview中的内容太长,外部布局将会延伸。我想在布局中使用固定大小的webview,但我不知道如何实现这一点。
聚苯乙烯。黑匣子的背景图片不是全屏。
有人会给我一些提示吗?
<?xml version="1.0" encoding="utf-8"?>
<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:background="@drawable/common_background" >
... some other layout ...
<LinearLayout
android:id="@+id/wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/wrapper_background" >
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp" />
</LinearLayout>
... some other layout ...
</RelativeLayout>
答案 0 :(得分:0)
请改用此代码
<LinearLayout
android:id="@+id/wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/someOtherLayout"
android:layout_centerInParent="true"
android:background="@drawable/wrapper_background" >
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp" />
</LinearLayout>
<Some Other Layout
android:id="@+id/someOtherLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
答案 1 :(得分:0)
使用
android:padding =“10dip”到webview的父级。
答案 2 :(得分:0)
请改用此代码
它将如图所示
xml代码:
<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:background="@drawable/ic_launcher" >
... some other layout ...
<LinearLayout
android:id="@+id/wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="@drawable/ic_launcher" >
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp" />
</LinearLayout>
... some other layout ...
</RelativeLayout>
答案 3 :(得分:0)
未经测试但您可以尝试:
<LinearLayout
android:id="@+id/wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="10dp"
android:background="@drawable/wrapper_background" >
答案 4 :(得分:0)
试试这个:
<?xml version="1.0" encoding="utf-8"?> <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:background="@drawable/common_background" > ... some other layout ... <LinearLayout android:id="@+id/wrapper" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerInParent="true" android:padding="10dip" <---- Apply this in your layout. android:background="@drawable/wrapper_background" > <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> ... some other layout ... </RelativeLayout>