我遇到了xml布局文件的问题,当试图在约束布局中添加admob banner和scrollView时,横幅出现在滚动视图上方请检查图像下方
这是我在main3activity的xml布局文件中使用的代码,但它不起作用
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
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="com.example.macbookpro.Main3Activity">
<ScrollView
android:id="@+id/scrollview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/title1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="2dp"
android:layout_marginStart="12dp"
android:layout_marginTop="55dp"
android:text="@string/title1"
android:textAllCaps="true"
android:textColor="@color/colorPrimaryDark"
android:textSize="25sp" />
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/soutitle3"
android:layout_marginEnd="12dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="12dp"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:text="@string/soutext3" />
<TextView
android:id="@+id/soutitle4"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/textView4"
android:layout_marginLeft="2dp"
android:layout_marginStart="8dp"
android:layout_marginTop="15dp"
android:text="@string/soutitle4"
android:textColor="@color/colorPrimaryDark"
android:textSize="18sp" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/soutitle4"
android:layout_marginEnd="12dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="12dp"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:text="@string/soutext4" />
<TextView
android:id="@+id/soutitle5"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/textView5"
android:layout_marginLeft="2dp"
android:layout_marginStart="8dp"
android:layout_marginTop="15dp"
android:text="@string/soutitle5"
android:textColor="@color/colorPrimaryDark"
android:textSize="18sp" />
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/soutitle5"
android:layout_marginEnd="12dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="12dp"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:text="@string/soutext5" />
</RelativeLayout>
</ScrollView>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-apppub3940256099942544/6300978111"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
我认为它反对谷歌的政策,把横幅放在文本上面,所以有什么建议吗?谢谢
我通过向scrollView添加android:layout_above =“@ + id / adView”解决了这个问题
也许ConstrainLayout不是最好的工具,我认为你应该使用RelativeLayout并使用如下的layaout_above:
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_above="@+id/scrollview1"
... />