Android 对齐Adview底部的Webview

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

我的Constraintlayout中有一个
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>