2013-03-16 3 views
1

je la vue suivante: enter image description hereImageView montrant les données précédente vue de l'image

dans lequel, si je clique sur une ImageButton Affiche l'image respective en plein écran mode.For exemple, si je clique sur noir, il montre une vue de l'image, comme: enter image description here

aussi je tâche de fond à la couleur plein écran pour certains imagebuttons comme ceci: si je clique rose, il montre la couleur rose clair:

enter image description here

Upto maintenant son tout ok, si je clique sur le bouton noir d'abord, puis je clique sur le rose, l'image sur le noir est porté à la mise en page avec un fond rose, comme ceci:

enter image description here

Ceci est mon problème, je veux seulement rose, pas l'image au premier plan;

Ceci est mon fichier XML:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:background="#657383" > 

<ImageView android:id="@+id/imv" 
     android:contentDescription="@string/app_name" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:visibility="gone" 
     /> 

<Button android:id="@+id/home" 
    android:contentDescription="@string/hello_world" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="20dp" 
    android:layout_marginTop="10dp" 
    android:text="@string/Back_Button" 
    android:textSize="25sp" 
    /> 


    <RelativeLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 


    <ImageButton android:id="@+id/image1" 
     android:contentDescription="@string/hello_world" 
     android:layout_width="130dp" 
     android:layout_height="95dp" 
     android:background="#000000" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="10dp"/> 

    <ImageButton android:id="@+id/image2" 
     android:contentDescription="@string/hello_world" 
     android:layout_width="130dp" 
     android:layout_height="95dp" 
     android:layout_toRightOf="@+id/image1" 
     android:background="#ff0000" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="10dp"/> 

    <ImageButton android:id="@+id/image3" 
     android:contentDescription="@string/hello_world" 
     android:layout_width="130dp" 
     android:layout_height="95dp" 
     android:layout_below="@+id/image1" 
     android:background="#00ff00" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="10dp" 
     /> 

    <ImageButton android:id="@+id/image4" 
     android:contentDescription="@string/hello_world" 
     android:layout_width="130dp" 
     android:layout_height="95dp" 
     android:background="#0000ff" 
     android:layout_below="@+id/image2" 
     android:layout_toRightOf="@+id/image3" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="10dp" 
     /> 

    <ImageButton android:id="@+id/image5" 
     android:contentDescription="@string/hello_world" 
     android:layout_width="130dp" 
     android:layout_height="95dp" 
     android:background="#FFFF00" 
     android:layout_below="@+id/image3" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="10dp" 
     /> 

    <ImageButton android:id="@+id/image6" 
     android:contentDescription="@string/hello_world" 
     android:layout_width="130dp" 
     android:layout_height="95dp" 
     android:layout_below="@+id/image4" 
     android:layout_toRightOf="@+id/image5" 
     android:background="#FFA500" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="10dp"/> 

    <ImageButton android:id="@+id/image7" 
     android:contentDescription="@string/hello_world" 
     android:layout_width="130dp" 
     android:layout_height="95dp" 
     android:layout_below="@+id/image5" 
     android:background="#FFFFFF" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="10dp"/> 

    <ImageButton android:id="@+id/image8" 
     android:contentDescription="@string/hello_world" 
     android:layout_width="130dp" 
     android:layout_height="95dp" 
     android:layout_below="@+id/image6" 
     android:background="#F52887" 
     android:layout_toRightOf="@+id/image7" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="10dp"/> 



</RelativeLayout> 

données Mon .java est:

 private OnClickListener myListener = new OnClickListener() { 

    @SuppressLint("NewApi") 
    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 


     try { 

      handler.postDelayed(new Runnable() { 

       @Override 
       public void run() { 
        // TODO Auto-generated method stub 
        iv.setVisibility(View.GONE); 
       } 
      }, 2500); 



      if (v.getId() == R.id.image1) { 
       iv.setBackground(null); 
       iv.setVisibility(View.VISIBLE); 
       iv.setImageResource(R.drawable.ic_launcher); 

      } else if(v.getId() == R.id.image2){ 
       iv.setBackground(null); 

       iv.setVisibility(View.VISIBLE); 
       iv.setImageResource(R.drawable.kids_paint_hands); 
      }else if(v.getId() == R.id.image3){ 

       iv.setBackground(null); 

       iv.setVisibility(View.VISIBLE); 
       iv.setImageResource(R.drawable.play_logo); 
      }else if(v.getId() == R.id.image4){ 

       iv.setBackground(null); 
       iv.setVisibility(View.VISIBLE); 
       iv.setBackgroundColor(Color.BLUE); 
      }else if(v.getId() == R.id.image5){ 

       iv.setBackground(null); 

       iv.setVisibility(View.VISIBLE); 
       iv.setBackgroundColor(Color.CYAN); 
      }else if(v.getId() == R.id.image6){ 

       iv.setBackground(null); 

       iv.setVisibility(View.VISIBLE); 
       iv.setBackgroundColor(Color.MAGENTA); 
      }else if(v.getId() == R.id.image7){ 

       iv.setBackground(null); 

       iv.setVisibility(View.VISIBLE); 
       iv.setBackgroundColor(Color.WHITE); 
      }else if(v.getId() == R.id.image8){ 

       iv.setBackground(null); 

       iv.setVisibility(View.VISIBLE); 
       iv.setBackgroundColor(Color.DKGRAY); 
       iv.clearFocus(); 
      } 






     } catch (Exception e) { 
      // TODO: handle exception 
      e.printStackTrace(); 
     } 

Toute aide ou suggestion?

+0

envoyer votre code, vous pouvez régler la visibilité de l'image pour aller – Pragnani

+0

S'il vous plaît ajouter votre code si vous faites passer de plein écran en cliquant sur le bouton, afin que nous puissions voir votre erreur le cas échéant, et vous aider. – Rekha

+0

@Pragnani: Juste mis à jour mon code avec Java classe – sai

Répondre

1

Essayez cette

Première

ImageResource is different from the background Resource. 

ImageResource is the foreground image, background resource is the background one. 

Vous devez faire comme ça

image.setImageResource(android.R.color.transparent); 

pour montrer l'image transparente au lieu d'origine un

+0

Merci beaucoup !!! Pragnani – sai

1

Votre image apparaît avec le changement d'arrière-plan parce que vous n'êtes pas la réinitialisation ImageResource attribut lorsque vous changez la couleur d'arrière-plan rose ou toute autre couleur unie en raison de laquelle votre image précédente apparaît aussi faire avec le nouveau fond. Pour résoudre ce problème, vous pouvez afficher l'image en tant qu'arrière-plan au lieu d'utiliser ImageResource ou vous devez supprimer l'imageResource que vous avez définie précédemment (exemple: iv.setImageResource (tout cadre transparent)).

+0

Ya, j'ai eu ça, mais comment ?? L'option iv.setImageResource() n'accepte que, tout ce que vous n'acceptez pas pour Imageview. – sai

+0

Thankyou Rekha, .La méthode ci-dessus @ Pragnani travaillé, le tien également la même chose .... – sai

+0

@Rekha +10 pour la première réponse .. – Pragnani

Questions connexes