Bonjour à tous,
J'aimerais centrer le contenu d'un LineairLayout sans déformer mon autre LineairLayout.
Je m'explique j'ai une listView composée d'une image et d'un textView.
Mes images sont placées à Gauche et mes text à droite des images.
J'aimerais centrer mon LineairLayout tous en conservant l'alignement vertical des images.
Voici mon code:
Ma listView:
Le contenu de ma listView:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@+id/listviewperso" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:fadeScrollbars="false" /> </LinearLayout>
Et ma méthode onCreate():
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 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="center_horizontal" > <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10px" /> <TextView android:id="@+id/titre" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16px" android:textStyle="bold" android:textColor="#FFF3A2"/> </LinearLayout> </LinearLayout>
Avec ce bous de code j'aligne le contenu de ma listView, mais mes images ne sont plus du tout aligné verticalement.
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 ListView maListViewPerso = (ListView) findViewById(R.id.listviewperso); ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>(); HashMap<String, String> map; map = new HashMap<String, String>(); map.put("titre", "Agenda Besançon ce jour"); map.put("img", String.valueOf(R.drawable.ic_launcher)); listItem.add(map); map = new HashMap<String, String>(); map.put("titre", "Agenda Besançon ce week-end"); map.put("img", String.valueOf(R.drawable.ic_launcher)); listItem.add(map); map = new HashMap<String, String>(); map.put("titre", "Les news"); map.put("img", String.valueOf(R.drawable.ic_launcher)); listItem.add(map); map = new HashMap<String, String>(); map.put("titre", "Cinéma"); map.put("img", String.valueOf(R.drawable.ic_launcher)); listItem.add(map); map = new HashMap<String, String>(); map.put("titre","Informations Commerce"); map.put("img", String.valueOf(R.drawable.ic_launcher)); listItem.add(map); map = new HashMap<String, String>(); map.put("titre","Offres d'emplois"); map.put("img", String.valueOf(R.drawable.ic_launcher)); listItem.add(map); map = new HashMap<String, String>(); map.put("titre", "Les petites annonces"); map.put("img", String.valueOf(R.drawable.ic_launcher)); listItem.add(map); SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.affichageitem, new String[] {"titre","img"}, new int[] { R.id.titre,R.id.img}); maListViewPerso.setAdapter(mSchedule);
Alors, comment puis-je faire?
Merci d'avance
Partager