2011-09-13 3 views
0

J'ai deux vues (annonces) et quand un réseau publicitaire n'a aucune annonce à montrer la vue est supposée retourner à admob comme une sauvegarde. La première vue est inmobi (je ne sais pas si cela a de la pertinence). Si j'empêche l'annonce inmobi d'échouer en activant les annonces de test sur la vue, l'affichage de l'annonce d'admonation est inversé, mais lorsque les annonces en direct sont activées, l'affichage ne retourne jamais même lorsque le rappel d'annonce a échoué. S'il vous plaît aider.Viewflipper dans android pas retournant tout le temps

@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()); 

} 

Et j'ai 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> 

Répondre

0

pas voir encore la question. Mais si vous avez besoin de basculer juste entre les mises en page, je peux fournir mon propre code comment utiliser la fonctionnalité de retournement. Vous devez d'abord créer des pages distinctes de vos futures mises en page, telles que page_1.xml dans le dossier res.layout.

<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> 

Une fois que vous avez fait, décrire un fichier main.xml y compris xml-pages externes:

<?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> 

Que n'oubliez pas dans le fichier de classe pour déclarer = vf (ViewFlipper) findViewById (R.id.ViewFlipper01); étape suivante, vous devez passer outre OnTouchEvent pour calculer les nouvelles coordonnées et montrant le flip-animation:

@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; 
    } 

Et le dernier - décrire une des méthodes d'animation qui mentionnés dans 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; 
} 

Ecrire similaire pour le reste dans/inverser les directions.

+0

Merci pour la réponse rapide. Votre code est très utile mais malheureusement je suppose que je n'ai pas bien décrit le problème et il ne répond pas à la question. J'ai un petit viewflipper avec deux mises en page qui contiennent des adviews de différents réseaux publicitaires et quand le premier échoue, la vue est censée retourner à la seconde lorsque j'appelle vf.shownext(); mais il ne se retourne jamais. Ce n'est que lorsque j'ouvre des publicités TEST pour le premier réseau que la vue passe correctement au deuxième réseau et je ne sais pas pourquoi. – Jason