Android 对齐Adview底部的Webview
我的Constraintlayout中有一个Android 对齐Adview底部的Webview,android,webview,admob,android-webview,adview,Android,Webview,Admob,Android Webview,Adview,我的Constraintlayout中有一个AdView和一个WebView。测试中出现的广告高度为90dp,但实际情况下可能为50dp或30dp,具体取决于分辨率屏幕。我使用android:layout_marginTop=“90dp”在AdView下对齐我的WebView 是否有办法以编程方式更改marginTop值,并根据所显示广告的高度将WebView垂直对齐在AdvView下 这是我的activity.xml <?xml version="1.0" e
AdView
和一个WebView
。测试中出现的广告高度为90dp,但实际情况下可能为50dp或30dp,具体取决于分辨率屏幕。我使用android:layout_marginTop=“90dp”
在AdView下对齐我的WebView
是否有办法以编程方式更改marginTop值,并根据所显示广告的高度将WebView
垂直对齐在AdvView
下
这是我的activity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<com.google.android.gms.ads.AdView
android:id="@+id/adView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/adview_border"
app:adSize="SMART_BANNER"
app:adUnitId="1232131231"
app:layout_constraintTop_toTopOf="parent">
<WebView
android:id="@+id/webview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="90dp"
android:layout_marginBottom="1dp"
>
</WebView>
非常感谢您的帮助。您需要在WebView
上使用layout\u constraintTop\u toBottomOf
,并根据AdMob对齐。以下是您可以尝试的示例代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.gms.ads.AdView
android:id="@+id/adView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/adview_border"
app:adSize="SMART_BANNER"
app:adUnitId="1232131231"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<WebView
android:id="@+id/webview1"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/adView1" />
</androidx.constraintlayout.widget.ConstraintLayout>