Android 包括列表下方的固定广告

Android 包括列表下方的固定广告,android,admob,ads,Android,Admob,Ads,我想在屏幕底部有一个固定广告的项目列表 这是迄今为止我所拥有的快速而肮脏的代码(还不包括广告): 公共类音板扩展ListActivity{ 私人SoundManager mSoundManager; /**在首次创建活动时调用*/ @凌驾 创建时的公共void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setListAdapter(新的ArrayAdapter(此,R.layout.soundboard_项,剪

我想在屏幕底部有一个固定广告的项目列表

这是迄今为止我所拥有的快速而肮脏的代码(还不包括广告):

公共类音板扩展ListActivity{
私人SoundManager mSoundManager;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setListAdapter(新的ArrayAdapter(此,R.layout.soundboard_项,剪辑_字符串));
ListView lv=getListView();
mSoundManager=newsoundmanager();
initSounds(getBaseContext());
mSoundManager.addSound(1,R.raw.bad_季节);
mSoundManager.addSound(2号,R.raw.friend_机场);
lv.setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
//单击后,显示带有文本视图文本的祝酒词
字符串选择;
选择=(字符串)((文本视图)视图).getText();
Toast.makeText(getApplicationContext(),((TextView)视图).getText(),Toast.LENGTH_SHORT.show();
如果(选择==“坏季节”)
mSoundManager.playSound(1);
如果(选择==“机场的朋友”)
mSoundManager.playSound(2);
}
});
}
@凌驾
公共布尔onKeyDown(int-keyCode,KeyEvent事件)
{
if((keyCode==KeyEvent.keyCode_HOME)){
完成();
}
if((keyCode==KeyEvent.keyCode\u BACK)){
完成();
}
返回super.onKeyDown(keyCode,event);
}
静态最终字符串[]剪辑\u字符串=新字符串[]{
“坏季节”,“机场的朋友”
};
}

我可能会使用Admob sdk。执行此操作的最佳方法是什么?

从AdMob SDK创建新的AdView,并将新视图设置为列表视图的页脚。比如:

lv.addFooterView(myAdMobView);
添加
setContentView(右布局、音板)到onCreate方法,然后在布局中创建两个XML文件:

soundboard.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
    <ListView
     android:id="@android:id/list"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:layout_weight="1"/>
    <include layout="@layout/ad"/>
</LinearLayout>


和ad.xml,其中将包含您的广告布局。

如果您正在寻找符合您要求的示例布局,请查看。

除了此答案,您还必须添加AdView AdView=(AdView)this.findViewById(R.id.AdView);和adView.loadAd(新地址());加载广告。真棒的回答谢谢!这是可行的,但请注意,它将继承该ListView的填充和边距
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
    <ListView
     android:id="@android:id/list"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:layout_weight="1"/>
    <include layout="@layout/ad"/>
</LinearLayout>