英文:
How do I seperate AdView and NestedScrollView from each other and stop them from overlaping in android studio?
问题
我试图在Android Studio中创建一个用于我的adView横幅广告的空间,但adView重叠在我的widget NestedScrollView上,并覆盖了位于NestedScrollView底部的文字。我的XML代码都包含在一个ConstraintLayout小部件中。如何分离adView和NestedScrollView小部件,使它们不重叠在一起?这是我的Android Studio activity_main.xml页面的当前格式:
<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"
android:orientation="vertical"
android:background="@color/grey"
tools:context=".MainActivity">
<androidx.core.widget.NestedScrollView
android:id="@+id/ScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.core.widget.NestedScrollView>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
</com.google.android.gms.ads.AdView>
</androidx.constraintlayout.widget.ConstraintLayout>
英文:
I am trying to create a space for my adView banner ad in android studio but the adView is overlapping my widget NestedScrollView, and is covering the words at the bottom which are in the NestedScrollView. All of my xml code is encased in a widget ConstraintLayout. How do I seperate the adView and NestedScrollView widget from overlapping one another? This is the current format of my android studio activity_main.xml page
<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"
android:orientation="vertical"
android:background="@color/grey"
tools:context=".MainActivity">
<androidx.core.widget.NestedScrollView
android:id="@+id/ScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.core.widget.NestedScrollView>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
</com.google.android.gms.ads.AdView>
</androidx.constraintlayout.widget.ConstraintLayout>
答案1
得分: 1
Your NestedScrollView的高度设置为match_parent,这使它与ConstraintSet的大小相同。
如果将其设置为0dp并将顶部约束到父项的顶部和底部约束到adView的顶部,它将与两者分开布局。
<androidx.core.widget.NestedScrollView
android:id="@+id/ScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/adView" >
英文:
Your NestedScrollView's height is set to match_parent this makes it the size of the ConstraintSet.
If you set it to 0dp and constrain top to top of the parent and bottom to top of the
adView it would layout with the two separated.
<androidx.core.widget.NestedScrollView
android:id="@+id/ScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/adView" >
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论