0
votes

Linearlayout Android: Layout_gravity = "Centre_vertical" fonctionne au moment de la conception mais ne fonctionne pas à l'heure

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/dice_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        app:srcCompat="@drawable/empty_dice"
        tools:src="@drawable/dice_1" />

    <Button
        android:id="@+id/roll_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/roll" />

</LinearLayout>
on design time i got the linearlayout centered verticaly , but when i test it on emulator or my device the linear layout is displayed at the top of the screen 

1 commentaires

Pourquoi n'allez-vous pas avec relativenelayout et utilisez CentreInparent = true


3 Réponses :


3
votes

dans votre linearlayout, changez Layout_gravity à juste gravité


1 commentaires

Merci Mike, mais pourquoi il n'y a pas de synchronisation entre la conception et le temps d'exécution?



2
votes

ne xxx

vous devez utiliser Android: Gravity =" Centre_vertical "

Placez l'objet dans le centre vertical de son conteneur, sans changer son Taille


3 commentaires

Android: Gravity définit la gravité du contenu (c'est-à-dire ses sous-visions) de la vue utilisée sur. Android: Layout_gravity définit la gravité de la vue ou de la mise en page par rapport à son parent. Donc ce n'est pas vrai ??? !!!


@ Sh.raai exactement.


@ Sh.raai a lu Stackoverflow.com/Questtions/3482742/...



0
votes

dans la mise en page:

Changer Android: Layout_height = "wrap_content"

à

android: layout_height = "match_parent"


0 commentaires