2012-03-28 59 views
0

我有一個「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視圖,但是它與內容視圖的下端重疊。所以有什麼辦法,我可以動態地將腳註添加到活動的內容視圖中。 我仍在解決方案,如果我發現任何我一定會發布。

在此先感謝

回答

0

把你最後的代碼片斷在ParentActivity:在OnCreate和定義a_child_activity:在OnCreate爲{/ *我創造的東西* /; super.onCreate(); }

只是一個初學者,所以可能垃圾儘管。

0

另外,我不知道你使用的一些setter有一個xml equivilent,刪除了代碼的一些需要?

相關問題