Android 如何使网络视图的宽度和高度为-10dp的父布局?
如何使webview的宽度和高度为-10dp,且具有背景图像的父布局如下图所示: 更新: 蓝色的盒子是屏幕。 黑框是外部布局(@+id/wrapper),红框是webview(@+id/webview) 绿色框是其他一些布局 我尝试了以下代码,但没有成功。 如果webview中的内容太长,则外部布局将拉伸。我希望在布局中有一个固定大小的webview,但我不知道如何实现这一点 另外,黑匣子的背景图像不是全屏的 有人能给我一些提示吗Android 如何使网络视图的宽度和高度为-10dp的父布局?,android,layout,webview,Android,Layout,Webview,如何使webview的宽度和高度为-10dp,且具有背景图像的父布局如下图所示: 更新: 蓝色的盒子是屏幕。 黑框是外部布局(@+id/wrapper),红框是webview(@+id/webview) 绿色框是其他一些布局 我尝试了以下代码,但没有成功。 如果webview中的内容太长,则外部布局将拉伸。我希望在布局中有一个固定大小的webview,但我不知道如何实现这一点 另外,黑匣子的背景图像不是全屏的 有人能给我一些提示吗 <?xml version="1.0" encoding
<?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>
... 其他一些布局。。。
... 其他一些布局。。。
请改用此代码
使用
android:padding=“10dip”指向webview的父级
请改用此代码
它将如图所示
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>
... 其他一些布局。。。
... 其他一些布局。。。
未测试,但您可以尝试以下方法:
<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" >
试试这个:
... 其他一些布局。。。
只需将android:layout\u height=“match\u parent”更新为xml文件我已经更新了我的问题,请查看图片。黑匣子的背景图像不是全屏的。@Hanon请检查我的更新答案,如果它仍然有效,请提供完整的xml源代码,请停止将您的视图称为黑匣子、绿匣子、红匣子等。这非常令人困惑。我已经更新了我的问题,请看图片。黑匣子的背景图片不是全屏的。我已经更新了我的问题,请看图片。黑匣子的背景图像不是全屏的。我已经尝试过这个解决方案,但仍然很有弹性。
<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" >
<?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>