2017-07-20 11 views
0

LinearLayout内で3つのビューをスライスしようとしています。しかし、Adviewは表示されません。ここに私のレイアウトファイルがあります。私は10に体重を与えて、3つの意見に分けました。Android Adviewが表示されない

<LinearLayout 
    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:weightSum="10" 
    tools:context="in.example.LandingActivity"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_weight="3" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:background="@drawable/landing_header_image" 
     android:layout_height="wrap_content"/> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewPager" 
     android:layout_width="match_parent" 
     android:layout_weight="4" 
     android:layout_height="wrap_content"> 
    </android.support.v4.view.ViewPager> 

    <com.google.android.gms.ads.AdView 
     xmlns:ads="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/adView" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_alignParentBottom="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="ca-app-pub-1390609726414683/1349170451" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentEnd="true"> 
    </com.google.android.gms.ads.AdView> 
</LinearLayout> 

私が迷っているものは何か。前もって感謝します。

答えて

0

ビューが3つあり、上、中央、下に配置したい場合は、次のように簡単に作成できるように相対レイアウトを使用する方がよいでしょう。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:adjustViewBounds="true" 
      android:background="@drawable/arrow_spinner" 
      android:scaleType="fitCenter" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true"> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/viewPager" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"></android.support.v4.view.ViewPager> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 

     <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/adView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      ads:adSize="BANNER" 
      ads:adUnitId="ca-app-pub-1390609726414683/1349170451"></com.google.android.gms.ads.AdView> 

    </LinearLayout> 

</RelativeLayout> 
0

その後、広告

mAdView = (AdView) findViewById(R.id.adView); 
AdRequest adRequest = new AdRequest.Builder().build(); 
mAdView.loadAd(adRequest); 

をロードして、あなたのadViewに

mAdView.setAdListener(new AdListener() { 
    @Override 
    public void onAdLoaded() { 
     // Code to be executed when an ad finishes loading. 
     Log.i("Ads", "onAdLoaded"); 
    } 

    @Override 
    public void onAdFailedToLoad(int errorCode) { 
     // Code to be executed when an ad request fails. 
     Log.i("Ads", "onAdFailedToLoad"); 
    } 

    @Override 
    public void onAdOpened() { 
     // Code to be executed when an ad opens an overlay that 
     // covers the screen. 
     Log.i("Ads", "onAdOpened"); 
    } 

    @Override 
    public void onAdLeftApplication() { 
     // Code to be executed when the user has left the app. 
     Log.i("Ads", "onAdLeftApplication"); 
    } 

    @Override 
    public void onAdClosed() { 
     // Code to be executed when when the user is about to return 
     // to the app after tapping on an ad. 
     Log.i("Ads", "onAdClosed"); 
    } 
}); 
0

あなたをAdListenerを追加することによって、そのがロードされたか失敗したかどうかをチェックしますが、これは

MobileAds.initialize(this, "YOUR_ADMOB_APP_ID"); 

を初期化し追加していることを確認します内部の子ビューにandroid:layout_weight="3"属性を使用していますLinearLayout 、あなたは0dpようなレイアウトの高さを指定する必要があります。

android:layout_height="0dp" 

はまた、この属性:

android:layout_alignParentEnd="true" 
android:layout_alignParentStart="true" 

のみRelativeLayout、ないLinearLayoutに使用されています。

0

wrap_contentの代わりに高さ0dpを設定します。 wrap_contentを設定すると、画面のサイズが必要になりますので、0dpに変更して確認してください。

関連する問題