在android中将webview高度设置为其父级的70%
我试图让webview只占据线性布局高度的70%,而广告横幅则占据剩下的30%。我的代码所做的是将webview宽度设置为70%,而不是高度。这是我的密码在android中将webview高度设置为其父级的70%,android,android-webview,android-linearlayout,Android,Android Webview,Android Linearlayout,我试图让webview只占据线性布局高度的70%,而广告横幅则占据剩下的30%。我的代码所做的是将webview宽度设置为70%,而不是高度。这是我的密码 <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/primary_light"> <WebView xmlns
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/primary_light">
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="7"
android:background="@android:color/transparent" />
<com.amazon.device.ads.AdLayout
android:id="@+id/adview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:layout_gravity="bottom" />
</LinearLayout>
我不确定我做错了什么,这里也有类似的问题,但解决方案似乎不起作用。也许我遗漏了一些明显的东西。
提前感谢。我认为这是因为线性布局的默认方向是水平的,这就是为什么权重属性应用于宽度而不是高度。在你的线性布局中使用这个,我认为它会解决你的问题
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"//This is the line that you need to add.
android:background="@color/primary_light">
尝试将webview的高度更改为match\u parent
。oops刚才注意到了一些事情……尝试将android:layout\u weight
更改为.7
和.3
而不是7
和3
。