3 pièce(s) jointe(s)
Multi floating boutons dans un coordinatorlayout en fonction d'une autre vue
Salut à tous,
J'ai un gros prolème avec 3 floating buttons dans un coordinatorlayout. The problème vient de 3 autres vues, qui peuvent être visible ou gone
Pièce jointe 396042
Pièce jointe 396046
Pièce jointe 396049
Sur les 3 écrans, on peut voir 3 possibilités: avec ou sans la barre DEUS, avec le slider
Les floatings sont positionnés comme s'il y avait à la fois le slider et la vue DEUS (qui est aussi un cas possible), mais ne bougent pas si les vues disparraissent ou non.
J'ai essayé plusieurs cas:
- avec anchor et anchorgravity par rapport à la barre DEUS, mais quand cette barre était en vue GONE, mes floating se retrouvaient en haut à gauche..
- sans anchor fonctionnait un peu mais n'est pas réactif au changement.
Pouvez vous m'aider à trouver une solution convenable pour positionner les floatings quelque soit les cas ?
Voici le layout:
Code:
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| <android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/appbar"
layout="@layout/layout_appbar" />
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/google_map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/lyt_floating_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@+id/frameLayout_deus"
app:layout_anchorGravity="top|end"
android:layout_marginEnd="@dimen/normal_spacing"
android:layout_marginBottom="186dp"
app:useCompatPadding="true"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add_find"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="@dimen/normal_spacing"
android:layout_marginStart="@dimen/normal_spacing"
android:onClick="clickAddHandleFinders"
android:src="@drawable/finds_plus"
app:backgroundTint="@color/black_xp" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_target_recentrer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="@dimen/normal_spacing"
android:layout_marginStart="@dimen/normal_spacing"
android:background="@android:color/white"
android:onClick="clickCenterMap"
android:src="@drawable/ic_gps_fixed_white_24dp"
app:backgroundTint="@color/black_xp" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginBottom="4dp"
android:layout_marginEnd="@dimen/normal_spacing"
android:layout_marginStart="@dimen/normal_spacing"
android:onClick="clickChangeMap"
android:src="@drawable/map_blanc"
app:backgroundTint="@color/black_xp" />
</LinearLayout>
<LinearLayout
android:id="@+id/frameLayout_deus"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:layout_marginBottom="130dp"
android:background="@color/colorAccent"
android:orientation="horizontal">
<TextView
android:id="@+id/text_view_deus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/normal_spacing"
android:layout_marginStart="@dimen/normal_spacing"
android:layout_weight="1"
android:drawablePadding="@dimen/normal_spacing"
android:drawableStart="@drawable/picto_deus_deconnected_red"
android:gravity="center"
android:text="@string/deus_not_connected"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/img_target"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:layout_margin="@dimen/normal_spacing"
android:onClick="goTargetsId"
android:src="@drawable/ic_bullseye" />
<ImageView
android:id="@+id/img_gear"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_gravity="center"
android:layout_marginEnd="16sp"
android:layout_marginStart="@dimen/normal_spacing"
android:onClick="goDeusSettings"
android:src="@drawable/ic_settings_gears" />
</LinearLayout>
<include
android:id="@+id/bottom_sheet"
layout="@layout/xprunning_bottom_sheet"
android:visibility="visible" />
</android.support.design.widget.CoordinatorLayout> |
Et le code pour gérer ca (c'est du kotlin):
Code:
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
| private fun initView() {
val deusParam = binding.frameLayoutDeus.layoutParams as CoordinatorLayout.LayoutParams
// Gère le slider
if (xpUser.mapTypeSecondary != null) {
deusParam.bottomMargin = (144 * density).toInt()
} else {
deusParam.bottomMargin = (96 * density).toInt()
}
if (!isDeusConnectionEnable()) {
fab_add_find.visibility = View.VISIBLE
deusParam.height = 0
} else {
fab_add_find.visibility = View.GONE
deusParam.height = (48 * density).toInt()
}
binding.frameLayoutDeus.layoutParams = deusParam
initPeekView()
}
private fun initPeekView() {
if (xpUser.mapTypeSecondary != null) {
layout_ign.visibility = View.VISIBLE
bottomSheetBehavior!!.peekHeight = (144 * density).toInt()
} else {
layout_ign.visibility = View.GONE
bottomSheetBehavior?.peekHeight = (96 * density).toInt()
}
} |