2

タイトル画面に adMob を追加することができました。このレイアウトは *.xml ファイルに記述されています。

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 を追加するにはどうすればよいですか?

4

1 に答える 1

0

あなたの質問から tttView が何であるか、またはそれがどのようにセットアップされているかは明らかではありませんが、表示するレイアウトタイプを作成する場合は、プログラムで AdView を LinearLayout に追加するか、次のように類似したものにすることができます:

    // 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 ファイルからレイアウトをロードしている場合は、上記と同様のことができます

    setContentView(R.layout.game); 

game.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"
>
<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>
于 2011-01-28T14:06:42.107 に答える