2

皆さん、これまでのところ、Admob を通常の線形レイアウトに実装することができました。今、私は追加を追加scrollviewし、adbanner消えました。それに対して何ができるかわかりません。

を追加した .xml のコードに従いますscrollview

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/linearLayout"
   android:orientation="vertical"
   android:layout_width="fill_parent" android:layout_height="match_parent">
   <ScrollView android:id="@+id/scrollView1" android:layout_height="wrap_content" android:layout_width="match_parent">
     <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent"   android:layout_height="match_parent" android:orientation="vertical">

     [whole bunch of layout elements whoch shouldn´t affect the adbanner]

     </LinearLayout>
   </ScrollView>    

私の線形レイアウトでは、adbanner が引き続き機能し、adbanner の位置全体がメインの activitiy.java ファイルで行われました (taiic.com のチュートリアルの助けを借りてこれを行いました)。

    // Lookup R.layout.main
    LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout); 

    // Create the adView
    // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
    String pubID = "xxxxxxxxxxxxxxxxxx";
    AdView adView = new AdView(this, AdSize.BANNER, pubID);

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

    // Initiate a generic request to load it with an ad
    AdRequest request = new AdRequest();
    request.setTesting(true);

    adView.loadAd(request);

admobバナーをに実装するときに、何を変更するか、またはどのコードを追加するかを誰か教えてもらえますscrollviewか?

編集:

私は追加しようとしました

<com.admob.android.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapprimaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
android:alignParentBottom="true"/>

.xml の最後の 2 行の間

  </LinearLayout>
     [here]
  </ScrollView>

しかし、その後、「エラー:XMLの解析中にエラーが発生しました:バインドされていないプレフィックス」というエラーが表示されます

乾杯

4

2 に答える 2

5

解析エラーについて:

これは質問のタイプミスですか?myapprimaryTextColor="#FFFFFF"の代わりにmyapp:primaryTextColor="#FFFFFF"。これにより、xml 解析エラーが発生します。


レイアウトについて:

RelativeLayout を使用します。作業コードは投稿の最後にあります。まず、いくつかの理論:)

ScrollView が画面全体を占めているため、admob ビューが表示されません。スクロールビューが定義されると、すべての画面が利用可能になるので、それを取ります。admob ビューは実際には画面のに描画されます。次の例で再現できます。

機能しないレイアウト

<?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/linearLayout"
   android:orientation="vertical"
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent">
   <ScrollView android:id="@+id/scrollView1" 
       android:layout_height="wrap_content" 
       android:layout_width="fill_parent">
         <LinearLayout android:id="@+id/linearLayout1" 
         android:layout_width="fill_parent"   
         android:layout_height="fill_parent" 
         android:orientation="vertical"
         >
            <EditText  
            android:layout_width="fill_parent" 
            android:layout_height="300dp" 
            android:text="Test1"
            />
            <EditText  
            android:layout_width="fill_parent" 
            android:layout_height="300dp" 
            android:text="Test2"
            />
            <EditText  
            android:layout_width="fill_parent" 
            android:layout_height="300dp" 
            android:text="Test3"
            />
         </LinearLayout>
   </ScrollView>    
        <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Test4"
        />
   </LinearLayout>

代わりに RelativeLayout を使用する場合は、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">
        <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Test4"
        android:id="@+id/test4"
        android:layout_alignParentBottom="true"
        />
       <ScrollView android:id="@+id/scrollView1" 
           android:layout_height="wrap_content" 
           android:layout_width="fill_parent"
           android:layout_above="@id/test4"
           >
         <LinearLayout android:id="@+id/linearLayout1" 
         android:layout_width="fill_parent"   
         android:layout_height="fill_parent" 
         android:orientation="vertical"
         >
            <EditText  
            android:layout_width="fill_parent" 
            android:layout_height="300dp" 
            android:text="Test1"
            />
            <EditText  
            android:layout_width="fill_parent" 
            android:layout_height="300dp" 
            android:text="Test2"
            />
            <EditText  
            android:layout_width="fill_parent" 
            android:layout_height="300dp" 
            android:text="Test3"
            />
         </LinearLayout>
       </ScrollView>    
   </RelativeLayout>
于 2011-05-12T20:34:11.983 に答える
1

私はadmob xmlバージョンを使用しました。それが私が使用しているもので、動作します。広告は上部にあります。コピーして貼り付けるだけで、すぐにスクロールできます。

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

    <com.google.ads.AdView android:id="@+id/adView"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           ads:adUnitId="a14dc1c9d6xxxxx"
                           ads:adSize="BANNER" />

    <ScrollView android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:fillViewport="true" > 

        [whole bunch of layout elements whoch shouldn´t affect the adbanner]

    </ScrollView>

</LinearLayout>
于 2011-05-12T20:10:04.920 に答える