2012-01-13 9 views
0

私はページの下部にadmobを配置しなければならないというレイアウトを設計しました。私はページの下にadmobを設定することができません。私は以下のコードを使用しています。どのように私はアンドロイドの私のページの下にadmobを設定できますか?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 



    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 

     > 

     <TableLayout 
     android:id="@+id/tableLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:paddingTop="30dp" 
     android:orientation="vertical" 
     > 

     <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <ImageView 
       android:id="@+id/train" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/atrd" /> 



      <ImageView 
       android:id="@+id/fares" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 

       android:src="@drawable/afrs" /> 

     </TableRow> 
     <TableRow 
       android:id="@+id/tableRow2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="FindTrains" /> 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:paddingLeft="5dp" 
       android:text="Fares" /> 

      </TableRow> 
      <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="wrap_content" 
      android:layout_marginTop="5dp" 
      android:layout_height="wrap_content" > 

      <ImageView 
       android:id="@+id/route" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/arts" /> 



      <ImageView 
       android:id="@+id/routemap" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/artms" /> 

     </TableRow> 
     <TableRow 
       android:id="@+id/tableRow2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Routes" /> 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:paddingLeft="5dp" 
       android:text="Routemap" /> 

      </TableRow> 
      <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="wrap_content" 
      android:layout_marginTop="5dp" 
      android:layout_height="wrap_content" > 

      <ImageView 
       android:id="@+id/enqury" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/aeqs" /> 



      <ImageView 
       android:id="@+id/information" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ainfs" /> 

     </TableRow> 
     <TableRow 
       android:id="@+id/tableRow2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Enqury" /> 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Information" 
       android:paddingLeft="5dp"/> 

      </TableRow> 
    </TableLayout> 
    </LinearLayout> 
    <LinearLayout 
      android:id="@+id/linearLayout2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      > 

      <com.admob.android.ads.AdView 
       android:id="@+id/adview" 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent" /> 

     </LinearLayout> 
</LinearLayout> 

誰でも私が間違っていたことを教えていただけますか?ありがとうございます。

答えて

2

は、ルートレイアウトとしてRelativeLayoutを取り、その後、アンドロイドとしてのLinearLayout(AdMobのビューが含まれている)に設定します。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

    <LinearLayout 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/relativeAd" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:gravity="center"> 

<com.google.ads.AdView android:id="@+id/adView" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         ads:adUnitId="@string/admob_id" 
         ads:adSize="BANNER" 
         ads:loadAdOnCreate="true" 
         /> 
     </LinearLayout> 

<!-- other codes here --> 

</RelativeLayout> 
layout_alignParentBottom = "true" を、例えばこれを見ます

これを試してください。

1

xmlの一番下にLinearLayoutという1つを宣言し、それにidを付けることができます。次のコードを記述し

@Override 
public void onCreate(Bundle savedInstanceState) { 
    // Create the adView 
    adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID); 

    // Lookup your LinearLayout assuming it’s been given 
    // the attribute android:id="@+id/mainLayout" 
    LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout); 

    // Add the adView to it 
    layout.addView(adView); 

    // Initiate a generic request to load it with an ad 
    adView.loadAd(new AdRequest()); 
} 

@Override 
public void onDestroy() { 
    adView.destroy(); 
    super.onDestroy(); 
} 
0

の属性をlinearLayout1に使用することもできます。このような

<LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" > 

     <TableLayout 
      ........ 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <com.admob.android.ads.AdView 
      android:id="@+id/adview" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 

これはあなたのコードを乱すことなく、あなたの問題を解決します。

関連する問題