2017-05-23 6 views
0

私は広告を画面の下部に配置しようとしています。 adsContentを配置したい画面から50dpをすべて使用するには、mainContent(フラグメントコンテナ)が必要です。 はここでのxmlがされています。このコードでDrawerLayoutを使用して画面の下部に広告が表示されませんか?

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


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

    <!-- The main content view --> 
    <LinearLayout 
     android:id="@+id/mainContent" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"/> 

    <LinearLayout 
     android:id="@+id/adsContent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:weightSum="1" 
     android:layout_above="@id/mainContent"> 
     <com.google.android.gms.ads.AdView 
      android:id="@+id/adView" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:minHeight="50dp" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_gravity="center|bottom" 
      android:layout_weight="5" 
      android:layout_marginBottom="10dp" 
      ads:adSize="SMART_BANNER" 
      ads:adUnitId="@string/banner_ad_unit_id"> </com.google.android.gms.ads.AdView> 
    </LinearLayout> 
</LinearLayout> 

<!-- The navigation drawer --> 
<RelativeLayout 
    android:id="@+id/drawerPane" 
    android:layout_width="280dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start"> 

    <!-- Profile Box --> 

    <RelativeLayout 
     android:id="@+id/profileBox" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:background="@color/gray" 
     android:padding="8dp"> 

     <ImageView 
      android:id="@+id/avatar" 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:layout_marginTop="15dp" 
      android:src="@drawable/ic_launcher" /> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="42dp" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="15dp" 
      android:layout_toRightOf="@+id/avatar" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/userName" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/home" 
       android:textColor="#fff" 
       android:textSize="12sp" 
       android:textStyle="bold" /> 
     </LinearLayout> 
    </RelativeLayout> 

    <!-- List of Actions (pages) --> 
    <ListView 
     android:id="@+id/navList" 
     android:layout_width="280dp" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/profileBox" 
     android:background="#ffffffff" 
     android:choiceMode="singleChoice" /> 
</RelativeLayout> 

`

広告が画面にありません。私がmainContentに499dpの高さを与えると、私は自分のスマートフォンの広告を見ることができ、それは正しく配置されていますが、他のスマートフォンはそうではありません。誰でも助けてくれますか?

答えて

0

1.使用RelativeLayoutあなたのコンテンツの一部をこのRelativeLayoutadsContentmainContentを置きます。

2.は、画面のbottomにそれを表示するためにadsContentに属性android:layout_alignParentBottom="true"を追加します。

3.adsContentレイアウト上にこれを表示するためにmainContentにattribuet android:layout_above="@id/adsContent"を追加します。ここで

は、作業コードです:

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

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:id="@+id/adsContent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:layout_alignParentBottom="true"> 

      <com.google.android.gms.ads.AdView 
       android:id="@+id/adView" 
       android:layout_width="fill_parent" 
       android:layout_height="50dp" 
       android:minHeight="50dp" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_gravity="center|bottom" 
       android:layout_weight="5" 
       ads:adSize="SMART_BANNER" 
       ads:adUnitId="@string/banner_ad_unit_id"> </com.google.android.gms.ads.AdView> 
     </LinearLayout> 

     <!-- The main content view --> 
     <LinearLayout 
      android:id="@+id/mainContent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@id/adsContent" 
      android:orientation="vertical"> 

     </LinearLayout> 
    </RelativeLayout> 

    <!-- The navigation drawer --> 
    <RelativeLayout 
     android:id="@+id/drawerPane" 
     android:layout_width="280dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start"> 

     <!-- Profile Box --> 

     <RelativeLayout 
      android:id="@+id/profileBox" 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:background="@color/gray" 
      android:padding="8dp"> 

      <ImageView 
       android:id="@+id/avatar" 
       android:layout_width="50dp" 
       android:layout_height="50dp" 
       android:layout_marginTop="15dp" 
       android:src="@drawable/ic_launcher" /> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="42dp" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="15dp" 
       android:layout_toRightOf="@+id/avatar" 
       android:orientation="vertical"> 

       <TextView 
        android:id="@+id/userName" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/home" 
        android:textColor="#fff" 
        android:textSize="12sp" 
        android:textStyle="bold" /> 
      </LinearLayout> 
     </RelativeLayout> 

     <!-- List of Actions (pages) --> 
     <ListView 
      android:id="@+id/navList" 
      android:layout_width="280dp" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/profileBox" 
      android:background="#ffffffff" 
      android:choiceMode="singleChoice" /> 
    </RelativeLayout> 
</android.support.v4.widget.DrawerLayout> 
+0

このソリューションは、作品...ありがとう! –

+0

それを知ってうれしい:) – FAT

関連する問題