2016-08-29 10 views
-1

アプリケーション内にフラグメントレイアウトで構成されたadViewを表示したい場合は、alignParentBottomがスクロール表示付きオフスクリーンで表示される

基本的には、もともと各フラグメントのレイアウトXML内にadViewを配置しようとしていました。これにより、adViewが画面からプッシュされるか、相対レイアウトコマンド(例:alignParentBottom)でうまく再生されなくなりました。

解決策は、自分のフラグメントに使用されているコーディネーターレイアウト外のメインアクティビティレイアウトにadViewを移動することでした。その後、コーディネーター・レイアウトとadViewを相対レイアウトにラップしました。

これで、adViewを完全に制御し、画面の下部に固定された各フラグメントに表示することができました。

+0

はなく、それはあなたが何をしたいあなたを与えると確信してますがどのような:ここで

は、編集したコードです'android:layout_above'の広告ビュー? – codeMagic

+0

私はあなたの提案を試みたときこれを得ました。エラー:(98、31)指定された名前( 'layout_above'、値 '@ id/adView')と一致するリソースが見つかりませんでした。 – DC5Gator

+0

あなたの問題は、AdViewがコード内のScrollViewの前にあることだと思います。 ScrollViewはAdViewを描画する必要があります。 AdViewをScrollViewの下に配置してみてください。また、広告ユニットIDとすべてが正しいことを確認してください。 – TheAnonymous010

答えて

1

私はあなたのScrollViewの背景を変更すると、AdViewを塗りつぶすことがわかりました。 AdViewをコード内のScrollViewの下に配置する必要があります。そうすることで、ScrollViewの後に描画されるため、上に表示されます。広告表示のための `alignParentBottom`を使用し、上記のあなたの` ScrollView`を揃える場合、私はテストしていない

<?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" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp"> 

    <!-- Dummy item to prevent EditTextView from receiving focus --> 
    <LinearLayout 
     android:id="@+id/dummyLayout" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:orientation="horizontal" /> 
    <!-- Dummy item to prevent EditTextView from receiving focus --> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

     <EditText 
      android:id="@+id/editText1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ems="4" 
      android:hint="@string/hint" 
      android:nextFocusLeft="@id/editText1" 
      android:nextFocusUp="@id/editText1" 
      android:singleLine="true"/> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/textView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/linearLayout1"/> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/textView4"/> 

    <TableLayout 
     android:id="@+id/tableLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/button1" 
     android:background="@color/colorAccent0" 
     android:stretchColumns="*"/> 

    <ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/tableLayout1" 
     android:layout_above="@+id/adView" 
     android:background="@color/colorGray"> 

     <TableLayout 
      android:id="@+id/tableLayout2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:stretchColumns="*"/> 
    </ScrollView> 

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

</RelativeLayout> 
+0

ありがとう!私はずっと古いSOのスレッドを読んだ後、スクロールビューの上にadviewを投げた。その前のことを逆転しようとしていたはずです。 – DC5Gator

+0

申し訳ありませんが、画面上にスクロールビューの下に表示されていたadviewを動かすと偽装されました。 – DC5Gator

+0

私は上に貼り付けたコードで私のデバイスに表示されてしまいました。たぶん 'android:layout_below =" @ + id/scrollView "も試してみてください。 – TheAnonymous010

関連する問題