简体   繁体   English

Admob广告未显示在adview上

[英]Admob ad not showing on adview

I am trying to put an adview to my app. 我正在尝试对我的应用进行adview。 I have put an adview on xml and is as follows 我在xml上添加了一个adview,如下


<?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:id="@+id/RelativeLayout1"   
android:layout_width="match_parent"   
android:layout_height="match_parent"   
android:orientation="vertical"
android:padding="10dp" >          

<ScrollView
    android:id="@+id/ScrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >

    <!-- Name Label -->

    <TextView
        android:id="@+id/name_label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="10dip"
        android:paddingTop="10dip"
        android:textSize="15sp"
        android:textStyle="bold" />    
</ScrollView>

 <com.google.android.gms.ads.AdView
     android:id="@+id/adView"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/ScrollView1"
     ads:adSize="BANNER"
     ads:adUnitId="ca-app-pub-6045707126584551/3116181621"
     android:layout_alignParentBottom="true" >
 </com.google.android.gms.ads.AdView>

</RelativeLayout>

and here is the code that i implemented in order to initialize adview in java. 这是我为了在Java中初始化adview而实现的代码。 This code is supposed to load the ads. 该代码应加载广告。


 public class SingleContactActivity extends Activity {

// JSON node keys
static final String ID = "id";
static final String POS = "position";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_single_contact);

    // getting intent data
    Intent in = getIntent();

    // Get JSON values from previous intent
    String name = in.getStringExtra(ID);

    // Displaying all values on the screen
    TextView lblName = (TextView) findViewById(R.id.name_label);

    lblName.setText(name);
     // Look up the AdView as a resource and load a request.
    AdView adView = (AdView)this.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("479004f857d93000").build();

    adView.loadAd(adRequest); 
}
}

The ad is not loading on the device when i try it. 当我尝试广告时,该广告未加载到设备上。 Any hint or help would be much appriciated. 任何提示或帮助将不胜枚举。 Thank you. 谢谢。

Oh i found the solutions. 哦,我找到了解决方案。 It was my first time using adview so got a little confusing. 这是我第一次使用adview,因此有些困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM