2013-11-26 6 views
2

내가 전 세계의 모든 코드를 tryed와 나는 2 가지 있어요 : 1) 오류 또는 2) 안되는 ..내 AdMob 광고를 보는 방법?

광고를 볼이 내 매니페스트입니다 :

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="18" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.example.adview.MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
<activity android:name="com.google.ads.AdActivity" 
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 
    </application> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
</manifest> 

업데이트 !!!! 은 **이 내 NEW 레이아웃입니다 : **

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"  
android:id="@+id/layout" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:text="@string/hello_world" /> 

<com.google.ads.AdView android:id="@+id/adView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    ads:adUnitId="xxxxxxxx" i put my editor id here.. 
    ads:loadAdOnCreate="true" 
    ads:adSize="BANNER"/> 

</RelativeLayout> 

그리고 ... 이 내 수업 (내가 레이아웃을했기 때문에 물건을 올려 그나마)

package com.example.adview; 



import android.os.Bundle; 
import com.google.ads.AdRequest; 
import com.google.ads.AdSize; 
import com.google.ads.AdView; 
import android.app.Activity; 
import android.view.Menu; 
import android.widget.LinearLayout; 

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 



} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

} 
입니다

GoogleAdMobAdsSdk-6.4.1 (최신 버전)을 라이브러리 및 프로젝트> RightClick> 속성> JavaBuildPath> AddExternalJARs> GoogleAdMobAdsSdk-6.4.1에 넣습니다.

답변

0
당신이 예를

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

xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads" 

을 추가 한 layout.xml 주요 활동에

당신은 당신의 광고 코드

ads:loadAdOnCreate="true"

+0

좋아하지만, 본건은 D를 작동합니다 내 배치는 다음과 같다 :

+0

안드로이드 : paddingRight ="activity_horizontal_margin @ DIMEN/activity_horizontal_margin " 안드로이드 : paddingTop ="DIMEN @를/activity_vertical_margin " 도구 : 문맥 ="MainActivity "> <텍스트 뷰 안드로이드 : layout_width =". wrap_content " 안드로이드 : layout_height ="wrap_content " 안드로이드 : layout_centerInParent ="true "로 안드로이드 : 텍스트 ="@ 문자열/hello_world "/> –

+0

@Jack K Fouani –

0

에 tihs 라인을 추가해야 이 정보를 AdView에 추가해야합니다 (

012).
ads:loadAdOnCreate="true" 

또는 프로그래밍 방식으로 추가 작업을로드해야합니다 (onCreate에서 제안 할 것입니다).

final AdView adView = findViewById(R.id.adView); 
adView.load(new AdRequest()); 
0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:id="@+id/ad_layout" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal"> 
    </LinearLayout> 

    ... Other View 

</LinearLayout> 

LinearLayout ad_layout = (LinearLayout) findViewById(R.id.ad_layout); 
ad_layout.setOrientation(LinearLayout.VERTICAL); 

mAdView = new AdView(this); 
mAdView.setAdSize(AdSize.BANNER); 
mAdView.setAdUnitId(UNIT_ID); 

AdRequest.Builder adRequest = new AdRequest.Builder(); 
adRequest.addTestDevice(AdRequest.DEVICE_ID_EMULATOR); 
adRequest.addTestDevice("3204995868e01153"); 
adRequest.addTestDevice("b9ceca537aaddee2"); 

ad_layout.addView(mAdView); 

mAdView.loadAd(adRequest.build()); 
관련 문제