我正在尝试将广告视频添加到我的应用中。我在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>
这是我为了在java中初始化adview而实现的代码。此代码应该加载广告。
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);
}
}
我尝试时,广告未在设备上加载。任何提示或帮助都会受到很大关注。 谢谢。
答案 0 :(得分:-4)
哦,我找到了解决方案。这是我第一次使用adview,所以有点混乱。