admob android help
i am having problems putting admob in the layout correctly. no matter how i put it i cant seem to see the ads at all. here are the 2 layouts...
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/and开发者_如何学Goroid"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000">
<ListView
android:id="@+id/android:list"
android:background="#0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1dip"/>
</LinearLayout>
layout2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="10dip"
android:background="#0000">
<TableLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:stretchColumns="*"
android:background="#0000">
<TableRow>
<TextView
android:id="@+id/description"
android:padding="2dip"
android:textColor="#ffff"
android:background="#0000"/>
</TableRow>
</TableLayout>
</LinearLayout>
and the code to the admob java is android:id="@+id/linearLayout" already in the main layout. the problem is that it doesnt display but if i make a new project with nothing but the admob java part with the layout online i can see the ads.
and yes i have added the proper codes in the main
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
also i was told to use relative layout but that also doesnt work unless i am doing it wrong. hope someone can help!
UPDATE1: here is the java code used by @+id/linearLayout to admob
// Lookup R.layout.main
LinearLayout layout =
(LinearLayout)findViewById(R.id.linearLayout);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
AdView adView = new AdView(this, AdSize.BANNER, "a14e458091154df");
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
In your main.xml add an AdView as per the example below, also don't forget to add the xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" to the main LinearLayout definition, and replace MY_AD_UNIT_ID with your adMob publisher ID
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000">
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<ListView
android:id="@+id/android:list"
android:background="#0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1dip"/>
</LinearLayout>
Also see more examples on this page.
精彩评论