2012-03-13 1 views
1

Мне нужен ясный пример того, как правильно установить andmob в моем приложении, очень озадачив, я смог выяснить, что я считал самой сложной частью, составлял его против 3.2 и устанавливал минимальный sdk на 7, который является минимальным sdk, на который я хотел бы нацеливаться.Как правильно установить admob, не отображаясь на некоторых тестовых телефонах

однако

, что я нахожу сейчас, что я могу заставить его работать на моей галактики записку, но на мой LG Optimus One и галактики Аполлоном, которые являются андроид 2,1 и 2,2 соответственно ни один из этих телефонов побежал объявления, на самом деле не уверены, как это имеет смысл, я также считаю, что документация admob является очень запутанной и неясной, я интерпретирую ее как говорящую, что разработчик может использовать либо чисто xml, либо просто java-код для этого, Ive использовал чисто xml вот мой код в моем манифесте для объявления

<activity 
     android:name="com.google.ads.AdActivity" 
     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> 

редактировать: расположение кода XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/title_color_dark" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center" 
    android:layout_marginTop="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:orientation="vertical" 
    android:paddingTop="8dp" > 

    <TextView 
     android:id="@+id/saysomething" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/loading" 
     android:textColor="#FFFFFF" 
     android:textSize="30dp" /> 

    <TextView 
     android:id="@+id/saysomethinginfo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:text="@string/loading" 
     android:textColor="#FFFFFF" 
     android:textSize="17dp" /> 

    <EditText 
     android:id="@+id/tweetedittext" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/edit_text" 
     android:gravity="top" 
     android:hint="@string/edittext_hint" 
      android:inputType="textCapSentences|textMultiLine|textAutoCorrect|textAutoComplete" 
     android:lines="4" 
     android:textAppearance="@style/TextAppearance.EditText" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:gravity="right" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/charactersremaining" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/characters" 
      android:textColor="#FFFFFF" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/posttweetbutton" 
      style="@style/TextAppearance.Button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="2dp" 
      android:background="@drawable/button_background" 
      android:onClick="posttweetbuttonClicked" 
      android:text="@string/postbuttonstext" 
      android:textSize="15dp" /> 
    </LinearLayout> 

    <com.google.ads.AdView 
     android:layout_marginTop="8dp" 
     android:id="@+id/adView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="a14f5be094d0328" 
     ads:loadAdOnCreate="true" /> 
</LinearLayout> 

редактировать 2 новая версия макета, делает диалог активности занимают весь экран, но все еще не показывает объявление

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/title_color_dark" > 

<LinearLayout 
    android:layout_alignParentTop="true" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginTop="8dp" 
    android:orientation="vertical" 
    android:paddingTop="8dp" > 

    <TextView 
     android:id="@+id/saysomething" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/loading" 
     android:textColor="#FFFFFF" 
     android:textSize="30dp" /> 

    <TextView 
     android:id="@+id/saysomethinginfo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:text="@string/loading" 
     android:textColor="#FFFFFF" 
     android:textSize="17dp" /> 

    <EditText 
     android:id="@+id/tweetedittext" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/edit_text" 
     android:gravity="top" 
     android:hint="@string/edittext_hint" 
     android:inputType="textCapSentences|textMultiLine|textAutoCorrect|textAutoComplete" 
     android:lines="4" 
     android:textAppearance="@style/TextAppearance.EditText" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:gravity="right" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/charactersremaining" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/characters" 
      android:textColor="#FFFFFF" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/posttweetbutton" 
      style="@style/TextAppearance.Button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="2dp" 
      android:background="@drawable/button_background" 
      android:onClick="posttweetbuttonClicked" 
      android:text="@string/postbuttonstext" 
      android:textSize="15dp" /> 
    </LinearLayout> 
</LinearLayout> 


<com.google.ads.AdView 
    android:id="@+id/adView" 
    android:layout_alignParentBottom="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"   
    ads:adSize="BANNER" 
    ads:adUnitId="a14f5be094d0328" 
    ads:loadAdOnCreate="true" /> 

редактировать 3 использует все линейные макеты без каких-либо ограничений по сторонам, но все равно не создают объявление

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/title_color_dark" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginTop="8dp" 
    android:orientation="vertical" 
    android:paddingTop="8dp" > 

    <TextView 
     android:id="@+id/saysomething" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/loading" 
     android:textColor="#FFFFFF" 
     android:textSize="30dp" /> 

    <TextView 
     android:id="@+id/saysomethinginfo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:text="@string/loading" 
     android:textColor="#FFFFFF" 
     android:textSize="17dp" /> 

    <EditText 
     android:id="@+id/tweetedittext" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/edit_text" 
     android:gravity="top" 
     android:hint="@string/edittext_hint" 
      android:inputType="textCapSentences|textMultiLine|textAutoCorrect|textAutoComplete" 
     android:lines="4" 
     android:textAppearance="@style/TextAppearance.EditText" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:gravity="right" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/charactersremaining" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/characters" 
      android:textColor="#FFFFFF" 
      android:textSize="20dp" /> 

     <Button 
      android:id="@+id/posttweetbutton" 
      style="@style/TextAppearance.Button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="2dp" 
      android:background="@drawable/button_background" 
      android:onClick="posttweetbuttonClicked" 
      android:text="@string/postbuttonstext" 
      android:textSize="15dp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="8dp" 
     android:orientation="vertical" > 

     <com.google.ads.AdView 
      android:id="@+id/adView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      ads:adSize="BANNER" 
      ads:adUnitId="a14f5be094d0328" 
      ads:loadAdOnCreate="true" /> 
    </LinearLayout> 
</LinearLayout> 

</LinearLayout> 
+0

выглядит хорошо до сих пор, можете ли вы разместить свой XML-код? –

+0

Кроме того, если вы можете описать то, что вы считаете запутанным, мы открыты для предложений о том, как сделать документацию более четкой. –

+0

Спасибо за ответ! Я включил код для макета: D –

ответ

2

AdView имеет ширину 320dp, что соответствует ширине экрана большинства телефонов в портретном режиме. AdView сидит внутри LinearLayout с android:layout_marginLeft="8dp" android:layout_marginRight="8dp", поэтому у него недостаточно ширины, чтобы показывать объявление.

Если вы проверяете журналы, то, вероятно, предупреждение, как:

Not enough space to show ad! Wants: 480, 75, Has: 456, 75

Чтобы решить эту проблему, вам необходимо либо удалить поля на вашем верхнем макете уровня или переместить AdView снаружи вашего верхнего уровня LinearLayout.

+0

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

+0

Вы не пытаетесь поместить объявление в диалоговом окне, не так ли? Если нет, я не думаю, что диалог является частью проблемы. Кроме того, как это урезало все в представлении? Я бы попытался использовать RelativeLayout верхнего уровня и выровнять AdView в нижней части экрана, а также весь твитер LinearLayout поверх AdView. –

+0

Я пробовал это, но я не получаю объявление для показа. Я редактировал свой первоначальный вопрос выше, с тем, как выглядит мой новый макет xml с относительной компоновкой в ​​качестве базового макета, однако он сделал операцию диалога на весь экран, который мог бы быть проблемой, потому что теперь объявление выходит за пределы поля зрения пользователей –

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

  • Нет связанных вопросов^_^