В случае LinearLayout
, поскольку вес был установлен на 1
, он занимал весь экран, когда объявление было еще не загружено . Тем не менее, вы должны увидеть предупреждение, подобное следующему в вашем logcat здесь.
W/Ads: Not enough space to show ad. Needs 320x50 dp, but only has 288x495 dp.
Чтобы решить эту проблему, вы можете использовать RelativeLayout
вместо LinearLayout
, как показано ниже.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/adview"
android:orientation="vertical"
android:padding="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:text="Contact us" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="email"
android:gravity="center"
android:selectAllOnFocus="false"
android:text="Email" />
</LinearLayout>
<LinearLayout
android:id="@+id/adview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<com.google.android.gms.ads.AdView
android:id="@+id/adview_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />
</LinearLayout>
</RelativeLayout>
С другой стороны, вы можете также рассмотреть возможность установки фиксированного размера для AdView
, чтобы он не скрывался, когда содержимое еще не загружено. Вы можете получить размеры разных типов рекламы для разных размеров экрана здесь .