在 android 中将 webview 高度设置为其父级的 70%
Set webview height to 70% of its parent in android
我试图让 webview 只占据线性布局高度的 70%,广告横幅占据剩余的 30%。我的代码所做的是将 webview 宽度设置为 70% 而不是高度。这是我的代码
<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 的默认方向是水平的,这就是将权重属性应用于宽度而不是高度的原因。在您的 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 只占据线性布局高度的 70%,广告横幅占据剩余的 30%。我的代码所做的是将 webview 宽度设置为 70% 而不是高度。这是我的代码
<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 的默认方向是水平的,这就是将权重属性应用于宽度而不是高度的原因。在您的 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">