2011-09-13 7 views
0

私は2つのビュー(広告)を持っていますが、1つの広告ネットワークに表示される広告がない場合、ビューはバックアップとしてadmobに切り替わります。最初のビューはinmobiです(関連性があるかどうかはわかりません)。インモビ広告を強制的に強制すると、ビュー上のテスト広告は反転して広告を表示しますが、ライブ広告をオンにすると、失敗した広告コールバックが受信されても​​ビューが反転することはありません。助けてください。アンドロイドのViewflipperは常に反転していません

@Override 
public void adRequestFailed(InMobiAdView arg0) { 
    // TODO Auto-generated method stub 
    Log.v("","inmobi ad request failed"); 

    // Initiate a generic request to load it with an ad 
    loadAdmob(); 
    ViewFlipper vf = (ViewFlipper) findViewById(R.id.ads); 

    vf.showNext(); 
} 

private void loadAdmob() { 

    AdView adView = new AdView(this, AdSize.BANNER, "xxxxxxxxxxx"); 

    LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout); 
    // Add the adView to it 
    layout.addView(adView); 
    adView.loadAd(new AdRequest()); 

} 

そしてXML

<ViewFlipper android:id="@+id/ads" 
    android:layout_width="320dip" 
    android:layout_height="50dip"> 

    <LinearLayout 
      android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 
    <com.inmobi.androidsdk.impl.InMobiAdView 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:id = "@+id/adview" 
    /> 
    </LinearLayout> 


    <LinearLayout 
    android:orientation="vertical" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:layout_gravity="center" 
    android:id="@+id/mainLayout" ></LinearLayout> 

    </ViewFlipper> 

答えて

0

私はまだ質問を参照していません。しかし、レイアウトの間をちょうど反転する必要がある場合は、フリップ機能を使用する方法を独自のコードで記述することができます。最初に、res.layoutフォルダにpage_1.xmlののような、今後のレイアウトの別のページを作成する必要があります。あなたが行われた後

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/GreenColor" 
    > 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center" 
     android:text="1" 
     android:textSize="120dip"> 
    </TextView> 
</LinearLayout> 

、外部のXML-ページを含むmain.xmlファイルについて説明します。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<ViewFlipper android:id="@+id/ViewFlipper01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <include android:id="@+id/libraryView1" layout="@layout/page_1" /> 
    <include android:id="@+id/libraryView2" layout="@layout/page_2" /> 
    <include android:id="@+id/libraryView3" layout="@layout/page_3" /> 
</ViewFlipper> 
</RelativeLayout> 

をVF =(ViewFlipper)findViewByIdを(宣言するクラスファイルに忘れないで行うよりもR.id.ViewFlipper01);

@Override 
    public boolean onTouchEvent(MotionEvent touchevent) { 
     switch (touchevent.getAction()) 
     { 
      case MotionEvent.ACTION_DOWN: 
      { 
       oldTouchValueX = touchevent.getX(); 
       oldTouchValueY = touchevent.getY(); 
       break; 
      } 
      case MotionEvent.ACTION_UP: 
      { 
       //if(this.searchOk==false) return false; 
       float currentX = touchevent.getX(); 
       float currentY = touchevent.getY(); 

       float deltaX = getAbs(oldTouchValueX - currentX); 
       float deltaY = getAbs(oldTouchValueY - currentY); 

       if (deltaX >= deltaY) 
       { 
        if (oldTouchValueX < currentX) 
        { 
         vf.setInAnimation(inFromLeftAnimation()); 
         vf.setOutAnimation(outToRightAnimation()); 
         vf.showNext(); 
        } 
        if (oldTouchValueX > currentX) 
        { 
         vf.setInAnimation(inFromRightAnimation()); 
         vf.setOutAnimation(outToLeftAnimation()); 
         vf.showPrevious(); 
        } 
       } //if deltaX 
       else 
        { 
        if (oldTouchValueY < currentY) 
        { 
         vf.setInAnimation(inFromUpAnimation()); 
         vf.setOutAnimation(outToDownAnimation()); 
         vf.showNext(); 

        } 
        if (oldTouchValueY > currentY) 
        { 
         vf.setInAnimation(inFromDownAnimation()); 
         vf.setOutAnimation(outToUpAnimation()); 
         vf.showPrevious(); 
        } 
       } //Else 
      break; 
      } 
     } 
     return false; 
    } 

そして最後の1 - OnTouchEventで述べたアニメーション方法を説明します:あなたは新しい座標を計算し、フリップアニメーションを示すためにOnTouchEventを上書きするべき 次のステップ

public static Animation inFromRightAnimation() 
{ 
    Animation inFromRight = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, 
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
    ); 
    inFromRight.setDuration(350); 
    inFromRight.setInterpolator(new AccelerateInterpolator()); 
    return inFromRight; 
} 

public static Animation outToLeftAnimation() 
{ 
    Animation outtoLeft = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f, 
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
    ); 
    outtoLeft.setDuration(350); 
    outtoLeft.setInterpolator(new AccelerateInterpolator()); 
    return outtoLeft; 
} 

がために同様の書き込み残りのイン/アウトフリップ方向。

+0

迅速な返信をありがとう。あなたのコードは非常に便利ですが、残念なことに私はよく問題を説明していないと思います。私は、異なる広告ネットワークの広告ビューを含む2つのレイアウトを持つ小さなviewflipperを持っています。最初に失敗すると、vf.shownext()を呼び出すとビューが2番目のものに切り替わります。しかしそれは決して反転しません。最初のネットワークのTEST広告をオンにした場合にのみ、ビューが2番目のネットワークに正しく反転し、その理由がわかりません。 – Jason

関連する問題