2010-12-10 4 views
2

* .xml 파일로 작성된 제목 화면에 adMob을 추가 할 수 있습니다.Android에서 ViewClass에 AdMob을 추가하는 방법

setContentView(R.layout.main); 
AdView adView = (AdView)findViewById(R.id.ad); 
adView.requestFreshAd(); 

main.xml에 다음이 포함

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:myapp="http://schemas.android.com/apk/res/de.xazen.tictactoe" 
     android:background="@drawable/title" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 
     <com.admob.android.ads.AdView 
       android:id="@+id/ad" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       myapp:backgroundColor="#000000" 
       myapp:primaryTextColor="#FFFFFF" 
       myapp:secondaryTextColor="#CCCCCC" 
       /> 
</RelativeLayout> 

게임 자체는 Tttview로 작성되었습니다.

public class TttView extends View 

활성 Game.java는 TttView의 인스턴스를 생성 및 배치로 사용의 setContent (tttView)를 사용한다.

public class Game extends Activity{ 

    private TttView tttView; 
    . 
    . 
    . 
    setContentView(tttView); 
} 

어떻게하면 게임 자체에 adMob을 추가 할 수 있습니까?

답변

0

음이 무엇인지 tttView 질문에서 명백하지 않거나 설정이지만,이 레이아웃 유형을 생성하는 경우 표시하는 방법 당신은있는 LinearLayout에 프로그램 적로 AdView를 추가하거나 수있는이 같은 유사한

// Setup layout parameters 
    LinearLayout.LayoutParams params; 
    params = new LinearLayout.LayoutParams(
      LinearLayout.LayoutParams.FILL_PARENT, 
      LinearLayout.LayoutParams.WRAP_CONTENT); 

    // Create a linear layout 
    LinearLayout layout = new LinearLayout(mContext); 
    layout.setOrientation(LinearLayout.VERTICAL); 
    layout.setPadding(6,6,6,6); 

    AdView mAdView = new AdView(this); 
    layout.addView(mAdView,params); 

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:myapp="http://schemas.android.com/apk/res/de.xazen.tictactoe" 
android:background="@drawable/title" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<tttView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ... 
    /> 
<com.admob.android.ads.AdView 
     android:id="@+id/ad" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     myapp:backgroundColor="#000000" 
     myapp:primaryTextColor="#FFFFFF" 
     myapp:secondaryTextColor="#CCCCCC" 
     /> 
</RelativeLayout> 
: XML 파일에서 레이아웃을로드하는 경우 또는 당신은 당신이 game.xml이

setContentView(R.layout.game); 

이상 무슨 유사한 작업을 수행 할 수 있습니다

관련 문제