J'ai des difficultés avec ma mise en page.Mise en page: image de fond streched
Comme mon premier projet de développement, j'essaye de faire un simple chronomètre. Je veux avoir une image d'un chronomètre en arrière-plan et le bouton de démarrage et d'arrêt au bas de l'application, côte à côte et en remplissant la largeur de l'écran.
Voici mon meilleur coup, mais je ne suis pas satisfait. Tous les widgets sont placés correctement, mais ... Mon arrière-plan est strié et mes boutons semblent compressés verticalement, même le texte en bas est un peu rogné.
Je trouve que si je change ces lignes
android:layout_width="fill_parent"
android:layout_height="fill_parent"
par
android:layout_width="wrap_content"
android:layout_height="wrap_content"
L'arrière-plan est ok, les boutons trop .. mais tous les widgets sont placés au centre de l'activité.
Comment puis-je résoudre ce problème? Par ailleurs, si je veux avoir mes boutons côte à côte, est-ce que j'ai choisi la meilleure solution?
Merci pour votre aide! Charles.
... et maintenant mon xml ....
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/background"
tools:context=".Chronosv1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="2" >
<Chronometer
android:id="@+id/chronometer1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="50"
android:text="START" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="50"
android:text="STOP" />
</LinearLayout>
J'ai essayé relativeLayout. Je ne sais pas comment avoir deux boutons de la même taille sans utiliser de rembourrage, je ne pense pas que ce soit une bonne idée si vous voulez que votre application fonctionne sur différents écrans.
De toute façon je trouve cela, mais j'ai toujours mon image streched et mes boutons n'ont pas la même taille.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
tools:context=".Chronosv1" >
<Chronometer
android:id="@+id/chronometer1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Start" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/button1"
android:text="Stop" />
1) Très probablement, vous aurez besoin de quelque chose de plus avancé que 'LinearLayout'; (2) Quel est votre composant 'chronomètre'? –
Chronmeter est un widget Android android.widget.Chronometer –