Après avoir appliqué les propriétés Gravity à mes éléments XML, ils ne semblent pas être positionnés au bon endroit. Comment ces problèmes peuvent être fixés de manière à ce que les conditions suivantes sont réunies ?:Mauvaise gravité appliquée aux éléments LinearLayout
- Le bouton doit être en haut de l'écran « déplacer vers le haut »
- Le bouton « déplacer vers le bas » doit être au bas de l'écran
- les
GridView
doit être au centre vertical de l'écran
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/btn_moveup"
android:text="move up"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="top"
/>
<GridView
android:id="@+id/abslistview_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:numColumns="auto_fit"
/>
<Button
android:id="@+id/btn_movedown"
android:text="move down"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="bottom"
/>
</LinearLayout>
UPDATE (suggestion akshay_shahane)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:weightSum="100"
tools:context=".MainActivity">
<Button
android:id="@+id/btn_moveup"
android:text="move up"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="5"
android:onClick="moveup_click"
/>
<GridView
android:id="@+id/abslistview_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="90"
android:layout_gravity="center_vertical"
android:numColumns="auto_fit"
/>
<Button
android:id="@+id/btn_movedown"
android:text="move down"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="5"
android:onClick="movedown_click"
/>
</LinearLayout>
pourquoi vous n'utilisez pas le poids? pour remonter 0,1, la grille 0,8 et descendre 0,1 –
@akshay_shahane Je l'ai fait mais la gravité de la GridView continue à jouer! Il ne va pas au centre vertical! – MacaronLover
a essayé de mettre la gravité de disposition de racine à centerVertical? –