我有一个“ParentActivity”的Android,我们可以添加一个页脚视图内容视图
public class ParentActivity extends Activity
和我的应用程序的所有活动扩展了这个ParentActivity
public class MainActivity extends ParentActivity
我有大约20项活动全部延伸亲子活动和所有活动有不同的布局彼此(如一些有的LinearLayout,一些RelativeLayout的,一些滚动型)
我的应用程序已接近完成,但我的客户现在需要有一个的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视图,但是它与内容视图的下端重叠。所以有什么办法,我可以动态地将脚注添加到活动的内容视图中。 我仍在解决方案,如果我发现任何我一定会发布。
在此先感谢