2017-02-15 6 views
0

У меня есть объявление AdMob в моем основном действии. Я хочу изменить поля элементов, чтобы при загрузке объявления они не перекрывались.Установить поле ListView в AdLoaded

@Override 
     public void onAdLoaded() { 
      Toast.makeText(getApplicationContext(), "Ad is loaded!", Toast.LENGTH_SHORT).show(); 
      bannerHeight = mAdView.getHeight(); 
      FrameLayout fm = (FrameLayout) findViewById(R.id.containerView); 
      DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams)fm.getLayoutParams(); 
      params.setMargins(0, 0, 0, bannerHeight); 
      fm.setLayoutParams(params); 
      ListView list = (ListView) findViewById(R.id.navList); 
      RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams)list.getLayoutParams(); 
      params.setMargins(0, 0, 0, bannerHeight); 
      list.setLayoutParams(params2); 
     } 

Первое изменение, поэтому контейнерView работает, но ListView остается неизменным. Я попытался дать ему marginBottom в xml, и это тоже работает. Что мне не хватает? Вот мой XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

<android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 


<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawerLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/containerView"> 
    </FrameLayout> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:id="@+id/drawerPane" 
     android:layout_gravity="start"> 

     <!-- List of Actions (pages) --> 
     <ListView 
      android:id="@+id/navList" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:choiceMode="singleChoice" 
      android:background="@color/busblue"/> 

    </RelativeLayout> 

</android.support.v4.widget.DrawerLayout> 

</LinearLayout> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     android:background="@color/background" 
     ads:adUnitId="@string/banner_main" 
     android:layout_alignParentBottom="true"> 
    </com.google.android.gms.ads.AdView> 

</RelativeLayout> 

ответ

0

Набор AdView снизу ListView & Set AdView обзорность GONE в XML, использование в качестве LinearLayout Родитель ListView & AdView вместо RelativeLayout

adView.setAdListener(new AdListener() { 
    @Override 
    public void onAdLoaded() { 
     super.onAdLoaded(); 
     adView.setVisibility(View.VISIBLE); 
    } 
    @Override 
    public void onAdFailedToLoad() { 
     super.onAdLoaded(); 
     adView.setVisibility(View.GONE); 
    } 
}); 
+0

Это не хорошо для меня, потому что тогда, когда объявление загружается, оно закрывает последнюю строку списка. –

+0

Попробуйте LinearLayout –

+0

это полезно? –

Смежные вопросы