enzostar Posted October 5, 2011 Share Posted October 5, 2011 Bonjour, je crée un bouton dynamiquement (au clic d'un utilisateur), je ne peux donc pas le créer en xml. Cependant, ce bouton occupe toute la place dont il dispose alors que j'aimerais qu'il n'occupe que la place dont il a besoin (attribut wrap_content en xml). J'ai essayé ceci, mais le bouton n'apparait carrément pas Resources res = getResources(); StateListDrawable myButton2 = new StateListDrawable(); myButton2.addState(new int[] { android.R.attr.state_pressed }, res.getDrawable(R.drawable.bsupprimerjoueur)); myButton2.addState(new int[] { android.R.attr.state_focused }, res.getDrawable(R.drawable.bsupprimerjoueur)); myButton2.addState(new int[] {}, res.getDrawable(R.drawable.bsupprimerjoueur)); Button supprimerJoueur = new Button(this); supprimerJoueur.setBackgroundDrawable(myButton2); supprimerJoueur.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,android.view.ViewGroup.LayoutParams.FILL_PARENT)); Merci pour votre aide Link to comment Share on other sites More sharing options...
chpil Posted October 5, 2011 Share Posted October 5, 2011 Dans ton code, remplace les LayoutParams.FILL_PARENT, par LayoutParams.WRAP_CONTENT Link to comment Share on other sites More sharing options...
enzostar Posted October 6, 2011 Author Share Posted October 6, 2011 Dans ton code, remplace les LayoutParams.FILL_PARENT, par LayoutParams.WRAP_CONTENT Dans ce cas là, mon bouton n'apparait même pas Link to comment Share on other sites More sharing options...
chpil Posted October 10, 2011 Share Posted October 10, 2011 Question peut-être idiote, tu ajoutes bien le bouton à la vue de ton Activity ? Je ne le voie pas dans ton extrait de code... Parce que j'ai testé, et avec WRAP_CONTENT, j'ai bien un bouton qui ne prend que la taille nécessaire... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.