【发布时间】:2012-04-11 20:43:16
【问题描述】:
我有一个'ParentActivity'
public class ParentActivity extends Activity
我的应用程序的所有活动都扩展了这个 ParentActivity
public class MainActivity extends ParentActivity
我有大约 20 个活动都在扩展 ParentActivity 并且所有活动都有不同的布局(比如有些有 LinearLayout,有些是 RelativeLayout,一些 ScrollView)
我的应用程序即将完成,但我的客户现在需要在每个活动结束时显示 adsense 广告。
一个通用的解决方案是包含以下布局到我的所有活动布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="30dip"
android:orientation="vertical"
android:background="@color/header_bgcolor"
android:gravity="bottom"
android:layout_gravity="bottom">
<com.google.ads.GoogleAdView
android:id ="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
但我想做的是在 ParentActivity 我将定义一个函数,它会自动将以下视图添加到内容视图的末尾,如下所示
ViewGroup view =(ViewGroup)this.findViewById(android.R.id.content);
View adSenseView = View.inflate(this, R.layout.ad_sense_layout,view);
GoogleAdView adView =(GoogleAdView)adSenseView.findViewById(R.id.adView);
AdSenseSpec adSenseSpec = new AdSenseSpec("CLIENT_ID")
.setCompanyName("COMPANY NAME")
.setAppName("APP NAME")
.setChannel("Channel Id")
.setAdType(AdType.TEXT);
adView.showAds(adSenseSpec);
通过这种方式,我可以在底部添加 adsense 视图,但它与内容视图的下端重叠。所以有什么办法,我可以动态地将页脚视图添加到内容中一个活动的视图。 我仍在研究解决方案,如果我找到任何解决方案,我一定会发布。
提前致谢
【问题讨论】:
标签: android dynamic view footer