IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Imagebutton n'affiche pas l'image


Sujet :

Android

  1. #1
    Membre à l'essai
    Inscrit en
    Février 2008
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 32
    Points : 17
    Points
    17
    Par défaut Imagebutton n'affiche pas l'image
    Bonjour à tous,

    Je suis en galère car je n'arrive pas à afficher l'image dans un ImageButton. J'ai testé avec une imageView et le problème est le même.

    Si je le fais dans le MainActivity, il n'y a pas de soucis tout fonctionne mais dans une autre class, il m'est impossible d'avoir l'image.
    J'ai juste le fond qui apparait.

    Quelqu'un aurait une idée du soucis ???

    Merci d'avance.

  2. #2
    Membre confirmé
    Avatar de BeeApps
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2017
    Messages
    86
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juillet 2017
    Messages : 86
    Points : 615
    Points
    615
    Par défaut
    Salut,

    Peux-tu poster ton code pour qu'on voit ce qui ne va pas ?

  3. #3
    Membre à l'essai
    Inscrit en
    Février 2008
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 32
    Points : 17
    Points
    17
    Par défaut
    Voici le fichier XML... L'imagebutton est en bas.
    Si je mets même code de l'imagebutton dans le activity_main ca marche.

    J'ai oublié de préciser, c'est qu'à l'aperçu j'ai bien l'image mais pas lors de l’exécution de programme.




    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="10">
     
     
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            android:background="@drawable/linearborder_bleu"
            android:layout_weight="0.5"
            >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:weightSum="10"
                android:orientation="horizontal">
     
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="14sp"
                    android:layout_gravity="center"
                    android:layout_weight="2"
                    android:layout_margin="5dp"
                    android:textColor="@color/colorAccent"
                    android:text="Type de vin : " />
     
            <Spinner
                    android:id="@+id/sp_type_vins"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="2dp"
                    android:layout_margin="5dp"
                    android:layout_weight="8"/>
     
            </LinearLayout>
     
            <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:weightSum="10"
                    android:orientation="horizontal">
     
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="14sp"
                    android:layout_gravity="center"
                    android:layout_weight="3.1"
                    android:layout_margin="5dp"
                    android:textColor="@color/colorAccent"
                    android:text="Pays : " />
     
            <Spinner
                    android:id="@+id/sp_pays"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="2dp"
                    android:layout_margin="5dp"
                    android:layout_weight="6.9" />
     
                </LinearLayout>
    </LinearLayout>
     
     
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="2dp"
        android:layout_marginBottom="5dp"
        android:layout_weight="1"
        android:weightSum="10"
        android:background="@drawable/linearborder_bleu"
      >
     
        <TextView
            android:id="@+id/textView2"
            android:layout_marginLeft="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="2.5"
            android:textColor="@color/colorAccent"
            android:text="Région" />
        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="5"
            android:textColor="@color/colorAccent"
            android:text="Nom" />
     
        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1.5"
            android:textColor="@color/colorAccent"
            android:text="Année" />
     
     
        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:textColor="@color/colorAccent"
            android:text="Qté" />
     
     
     
     
     
    </LinearLayout>
     
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:orientation="vertical"
            android:layout_margin="2dp"
            android:background="@drawable/linearborder_bleu"
            android:layout_weight="6"
     
            >
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
     
           >
    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listview"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true">
     
    </ListView>
     
     
        </RelativeLayout>
     
    </LinearLayout>
     
        <ImageButton
            android:id="@+id/BT_liste_vins"
            android:layout_width="25pt"
            android:layout_height="25pt"
            android:scaleType="centerInside"
            android:layout_gravity="center"
            android:background="@color/transparent"
            app:srcCompat="@drawable/todo_list" />
     
    </LinearLayout>

  4. #4
    Membre confirmé
    Avatar de BeeApps
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2017
    Messages
    86
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juillet 2017
    Messages : 86
    Points : 615
    Points
    615
    Par défaut
    Si j'ai bien compris, l'image s'affiche bien si tu l'initialises en Java, mais ne fonctionne pas si tu l'initialises uniquement dans le XML.

    Essaye de remplacer
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    app:srcCompat="@drawable/todo_list"
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    android:src="@drawable/todo_list"

  5. #5
    Membre à l'essai
    Inscrit en
    Février 2008
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 32
    Points : 17
    Points
    17
    Par défaut
    Alors avec ce code ça fonctionne impeccable. Merci du tuyau et de la rapidité.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    android:src="@drawable/todo_list"

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [GD] ImagePng qui ne m'affiche pas l'image
    Par AlineWW dans le forum Bibliothèques et frameworks
    Réponses: 6
    Dernier message: 29/11/2006, 03h38
  2. [Tcl/Tk] Mon interface n'affiche pas les images
    Par randazar dans le forum Tcl/Tk
    Réponses: 1
    Dernier message: 21/11/2006, 16h48
  3. n'affiche pas une image arriere plan definis dans une CSS
    Par mikebranque dans le forum Mise en page CSS
    Réponses: 5
    Dernier message: 30/06/2006, 15h54
  4. Navigateur : parfois n'affiche pas l'image
    Par tiboleo dans le forum Autres Logiciels
    Réponses: 3
    Dernier message: 09/06/2006, 17h27
  5. Word n'affiche pas les images de mon état
    Par maxdwarf dans le forum Access
    Réponses: 2
    Dernier message: 07/06/2006, 13h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo