0
我的主要活動中有一個AdMob廣告。我想更改項目的邊距,以便在加載廣告時不會重疊。在AdLoaded上設置ListView邊距
@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);
}
第一次更改,所以containerView工作,但ListView保持不變。我試圖在xml中給它一個marginBottom,這也起作用。我錯過了什麼?這裏是我的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>
的家長說不好對我來說,因爲當廣告被加載時它覆蓋了列表視圖的最後一行。 –
嘗試使用LinearLayout –
對您有幫助嗎? –