J'ai une disposition de barre d'outils réductrice qui présente 2 problèmes:
1) il est statique et ne s'effondre pas et je ne trouve pas la raison pour laquelle
2) la dernière ligne de la vue de recyclage est affichée à mi-chemin hors écran, je pense qu'elle devrait être corrigée une que l'effondrement est corrigé?
Code XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="match_parent"
tools:context=".Controllers.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/AppBarLayout"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
app:contentScrim="@color/colorPrimary"
app:title="Hero Title">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hero Title"
android:textStyle="bold"
android:textSize="20dp"
android:textColor="#ffffff"/>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="150dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/herosRecyclerView"
android:layout_width="395dp"
android:layout_height="715dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.design.widget.CoordinatorLayout>
et voici une image de ce que j'entends par moitié hors écran:
3 Réponses :
Veuillez essayer ceci. Ça va marcher.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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="match_parent"
android:background="@color/colorWhite"
tools:context=".Controllers.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/AppBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:textAlignment="center"
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:title="Hero Title">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#000000"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/herosRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
avez-vous supprimé la vue de texte dans un but?
agit de la même manière et ne change rien. pourriez-vous s'il vous plaît expliquer ce que j'ai fait de mal ou ce qui me manque pour que je puisse mieux vous comprendre
Parce que vous n'avez pas besoin d'ajouter une autre vue de texte car vous avez déjà défini du texte dans votre barre d'outils de réduction. Ce sera mieux. Voir l'effet de défilement.
Essayez de faire défiler en touchant la partie de la barre d'outils à l'écran. Vous pouvez voir l'effet.
juste essayé, n'a pas fonctionné. mon objectif est que lorsque vous faites défiler la vue de recyclage vers le bas, la barre s'effondre et lorsqu'elle atteint la fin, elle se rouvre à nouveau. c'est ce que vous vouliez dire?
bien, tant pis - fonctionne. fait quelques erreurs ici et là. Merci!
pouvez-vous s'il vous plaît souligner la différence entre ma version et la vôtre?
Je ne sais pas pourquoi j'ai obtenu -1 sur ce problème, si vous pouvez me voter pour parce que je ne vois pas de raison à cela
Salut. Cela semble fonctionner lorsque j'essaye de faire défiler la barre d'outils. Puis-je obtenir le même effet en essayant de faire défiler la vue de recyclage à la place?
Veuillez ajouter ceci à votre ImageView:
app:layout_collapseMode="parallax"
Le code ressemblera à ceci:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:fitsSystemWindows="true"
android:layout_height="192dp"
android:layout_width="match_parent">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:toolbarId="@+id/toolbar"
app:title="@string/app_name"
app:layout_scrollFlags="snap|scroll|exitUntilCollapsed"
app:layout_scrollInterpolator="@android:anim/decelerate_interpolator"
app:contentScrim="?attr/colorPrimary">
<ImageView
android:id="@+id/app_bar_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ss"
android:scaleType="centerCrop" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
app:collapseIcon="@drawable/ic_baseline_menu_24"
app:navigationIcon="@drawable/ic_baseline_menu_24"
android:layout_width="match_parent"
app:layout_collapseMode="pin"
app:menu="@menu/demo_menu">
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="@string/ipsum">
</TextView>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
pour une visite complète du tutoriel:
https://bedevelopers.tech/collapsing-toolbar-android-example-using-android-studio/