Pierre87 Posted May 25, 2010 Share Posted May 25, 2010 C'est un layout utilisé dans une ListView Je l'ai un poil simplifié pour l'exemple xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> android:orientation="vertical" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1"> android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" /> android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_margin="5dip" android:orientation="vertical"> android:id="@+id/comment" android:layout_width="30dip" android:layout_height="30dip" /> android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> android:id="@+id/friends" android:layout_width="20dip" android:layout_height="20dip" android:src="@drawable/lock" android:layout_gravity="bottom" /> J'ai donc un linear layout horizontal contenant : - Un linear layout contenant du texte (sur plusieurs lignes, de taille variable), il prend toute la place disponible - un linear layout vertical, sa largeur s'adapte à son contenu, dans lequel je veux placer : - une image en haut - une image en bas Le problème, c'est que je n'arrive pas à avoir une image en haut, et l'autre en bas. Soit j'ai les 2 en haut Soit elles sont bien placées, mais si le texte est trop petit, les 2 images se chevauchent -.- Vous avez une idée ? merci ! Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted May 25, 2010 Author Share Posted May 25, 2010 un ptit dessin : Quote Link to comment Share on other sites More sharing options...
Axel Posted May 25, 2010 Share Posted May 25, 2010 En changeant de type de layout? Exemple avec un RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> android:id="@+id/text" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true" android:layout_toLeftOf="@id/image_droite" /> android:id="@+id/image_droite" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_margin="5dip" android:orientation="vertical" android:layout_alignParentRight="true" > android:id="@+id/comment" android:layout_width="wrap_content" android:layout_height="wrap_content" /> android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="bottom"> android:id="@+id/friends" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/lock" /> Quote Link to comment Share on other sites More sharing options...
Axel Posted May 25, 2010 Share Posted May 25, 2010 Je n'ai pas le sdk sous la main pour tester donc il est possible qu'il y est quelques modifs à faire... Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted May 25, 2010 Author Share Posted May 25, 2010 je suis pas vraiment "pour" le RelativeLayout il me semble qu'il n'est pas super optimisé avant Android 2.0 donc je préfère utiliser le LinearLayout Quote Link to comment Share on other sites More sharing options...
Profete162 Posted May 25, 2010 Share Posted May 25, 2010 Je pense que tu abuses largement des layout.. Tu en a fais de trop. Essaye un LL horizontal qui contient un textview et un LL vertical. Le second LL vertical contient lui 2 images de gravité top et bottom. il faut simplifier au maximum ton xml. Edit: En fait ce que je dis est exactement la meme chose qu'axel, sauf que tu remplaces son relative layout par un linear layout! Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted May 25, 2010 Author Share Posted May 25, 2010 ouais, mais c'est dejà plus ou moins ce que j'ai les LinearLayout en trop, c'est parce que j'ai au moins 5 autres éléments en plus :P je vais essayer ton truc Profete, mais je crois que c'etait ce que je faisais lors de mon premier essai et ça me "collait" mes 2 images en haut :/ j'ai l'impression que sur un LinearLayout vertical, on ne peut influer que sur le positionnement droite/gauche (horizontal) des éléments... je me trompe ? Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted May 25, 2010 Author Share Posted May 25, 2010 @profete : je la règle où la gravity ? sur quels éléments ? et avec quels paramètres ? j'ai un doute :/ Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted May 25, 2010 Author Share Posted May 25, 2010 voilà à quoi ressemble mon LinearLayout situé à droite je n'ai pas vraiment 2 images, mais c'est pareil :P android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dip" android:orientation="vertical"> android:id="@+id/comment" android:layout_width="30dip" android:layout_height="30dip" android:layout_gravity="top"> android:id="@+id/comment_icon" android:layout_width="30dip" android:layout_height="30dip" /> android:id="@+id/comment_count" android:layout_width="30dip" android:layout_height="22dip" android:textColor="#fff" android:gravity="center" /> android:id="@+id/friends_only" android:layout_width="20dip" android:layout_height="20dip" android:src="@drawable/lock" android:layout_gravity="bottom" /> tous les Layout "au dessus" on un "layout_height" à "wrap_content" je me doute que c'est à cause de ça que ça ne marche pas mais si je les mets à "fill_parent", j'ai des chevauchements dans mes layouts :'( je sais que c'est un peu moche pour le FrameLayout, mais c'est temporaire :D Quote Link to comment Share on other sites More sharing options...
naholyr Posted May 25, 2010 Share Posted May 25, 2010 (edited) Je suis d'avis que tu pourras simplifier ça en restant sur des LinearLayout et en jouant sur les layout_weight pour "caler" les éléments. Genre : horizontal +-----------------+---------------+ | |vertical | | |+-------------+| | || weight = 1 || | |+-------------+| | || weight = 0 || | || || | || || | |+-------------+| | || weight = 1 || | |+-------------+| +-----------------+---------------+ Ça ferait 2 LineraLayout imbriqués pour la mise en forme, et le reste c'est tes éléments actifs, donc ça ne me semble pas énorme pour une UI... Edited May 25, 2010 by naholyr Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted May 25, 2010 Author Share Posted May 25, 2010 ha ouais ... une View vide au mileu, qui s'adapte à la taille ? j'y avais pas pensé c'est un peu moche, mais ça devrait marcher merci ! Quote Link to comment Share on other sites More sharing options...
naholyr Posted May 25, 2010 Share Posted May 25, 2010 Ah j'avais cru que tu avais une vraie view au milieu ^^ Donc ben oui, un view vide effectivement. Et histoire de respecter la culture web de Google, un petit clear.png d'1 px à 100% de transparence et une ImageView ? x] Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted May 25, 2010 Author Share Posted May 25, 2010 ou un simple LinearLayout vide ? Quote Link to comment Share on other sites More sharing options...
naholyr Posted May 25, 2010 Share Posted May 25, 2010 Ce qui prend le moins de mémoire, essaie avec un simple "View" peut-être. Mais du coup ça n'est pas aussi propre que je ne le pensais :( mais bon ça fait toujours une imbrication de moins que les solutions précédentes... Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted May 25, 2010 Author Share Posted May 25, 2010 au final j'ai ça : android:layout_width="wrap_content" android:layout_height="fill_parent" <------ paramètre qui pose problème android:layout_margin="5dip" android:orientation="vertical"> android:id="@+id/comment" android:layout_width="30dip" android:layout_height="30dip"> android:id="@+id/comment_icon" android:layout_width="30dip" android:layout_height="30dip" /> android:id="@+id/comment_count" android:layout_width="30dip" android:layout_height="22dip" android:textColor="#fff" android:gravity="center" /> android:layout_width="wrap_content" android:layout_height="0dip" android:layout_weight="1" /> android:id="@+id/friends_only" android:layout_width="20dip" android:layout_height="20dip" android:src="@drawable/lock" /> je rappelle que c'est juste une partie du layout d'une ligne dans une ListView ça marche, mais pas toujours :D tout dépend du "android:layout_height" du LinearLayout (celui le plus à l'extérieur dans mon code) si je suis en "wrap_content", ça ne va pas, le LinearLayout au milieu ne peut pas s'étendre, et tout est collé en haut si je suis en "fill_parent", c'est ok dans la plupart des cas, sauf si le reste du contenu de ma ligne est moins haut que le LinearLayout en gros, j'ai mon FrameLayout qui vient "écraser" mon ImageView Je crois que mon problème est insoluble :'( Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.