Boujour
Je cherche à connaitre la hauteur de la barre de titre de l'application pour centrer mes widgets par rapport à l'espace restant.
Une idée ?
merci![]()
Boujour
Je cherche à connaitre la hauteur de la barre de titre de l'application pour centrer mes widgets par rapport à l'espace restant.
Une idée ?
merci![]()
Si voila mon code :
Il y a 4 boutons dont la taille doit être la même et ils doivent occuper toutes la fenêtre.
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 super.onCreate(savedInstanceState); setContentView(R.layout.main); WindowManager wm=(WindowManager)getSystemService(WINDOW_SERVICE); Display display= wm.getDefaultDisplay(); int height = display.getHeight(); int width = display.getWidth(); // pour information height = height - 50; final Button button1 = (Button) findViewById(R.id.Button01); button1.setHeight(height/4); final Button button2 = (Button) findViewById(R.id.Button02); button2.setHeight(height/4); final Button button3 = (Button) findViewById(R.id.Button03); button3.setHeight(height/4); final Button button4 = (Button) findViewById(R.id.Button04); button4.setHeight(height/4);
Pour y arriver j'ai du "tricher"en utilisant :
height = height - 50;
ce que je voudrais éviter
tu peut monter ton fichier xml?
EN gros tu veut que tes 4 boutons se partagent l'espace? As tu essayé avec les poids?
Oui c'est ce que je voudrais.
Je vais essayer les poids
Voici mon fichier xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <?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" > <Button android:id="@+id/Button01" android:layout_height="wrap_content" android:text="@string/bt1_text" android:layout_width="fill_parent"></Button> <Button android:id="@+id/Button02" android:layout_height="wrap_content" android:text="@string/bt2_text" android:layout_width="fill_parent"></Button> <Button android:id="@+id/Button03" android:layout_height="wrap_content" android:text="@string/bt3_text" android:layout_width="fill_parent"></Button> <Button android:id="@+id/Button04" android:layout_height="wrap_content" android:text="@string/bt4_text" android:layout_width="fill_parent"></Button> </LinearLayout>
avec le même poids
pourquoi il te fallait enlever 50 à la hauteur?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <?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" > <Button android:id="@+id/Button01" android:layout_height="wrap_content" android:text="@string/bt1_text" android:layout_width="fill_parent" android:layout_weight="1"></Button> <Button android:id="@+id/Button02" android:layout_height="wrap_content" android:text="@string/bt2_text" android:layout_width="fill_parent" android:layout_weight="1"></Button> <Button android:id="@+id/Button03" android:layout_height="wrap_content" android:text="@string/bt3_text" android:layout_width="fill_parent" android:layout_weight="1"></Button> <Button android:id="@+id/Button04" android:layout_height="wrap_content" android:text="@string/bt4_text" android:layout_width="fill_parent" android:layout_weight="1"></Button> </LinearLayout>
J'enlevais 50 pixel à la hauteur pour prendre en compte la barre de titre mais c'était une mauvais méthode d'où ma question
J'ai testé avec les poids et cela fonctionne nickel
Merci du coup de main
Partager