/ / Jak przenieść widok tekstu do tytułu na rozwijanym pasku narzędzi? - Android, Android-pasek narzędzi, składanie do paska narzędzi

Jak uzyskać przejście tekstowe do tytułu na zwijanym pasku narzędzi? - Android, android-toolbar, zwijanie, gra w dziesiątkę

mam CollapsingToolbarLayout który zawiera TextView i a RatingBar pod TextView. Czy byłoby możliwe, aby mieć TextView jakoś przejść do tytułu?

Mój obecny układ wygląda następująco: wprowadź opis obrazu tutaj

Chcę, aby „Tytuł” ​​pojawił się jako pasek narzędzizałamuje się. Pojawi się również przycisk Wstecz, więc w jaki sposób zapewniłem przejście widoku tekstowego do odpowiedniego miejsca (po prawej stronie przycisku Wstecz)?

EDYCJA: Oto mój XML

<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="@dimen/detail_view_app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="@style/CollapsingToolbarLayoutExpandedTextStyle"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="@dimen/double_margin"
android:gravity="center_vertical"
android:orientation="vertical"
app:layout_collapseMode="parallax">

<TextView
android:id="@+id/title"
fontPath="fonts/OpenSans-Bold.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textColor="@android:color/white"
android:textSize="@dimen/large_text"/>

<RatingBar
android:id="@+id/rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</LinearLayout>

</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

Odpowiedzi:

6 dla odpowiedzi № 1

Rozwiązaniem jest: Nie używaj TextView.

Korzystając z nich, możesz umieścić rozwinięty tytuł w dowolnym miejscu CollapsingToolbarLayout atrybuty:

app:expandedTitleGravity        default is bottom|left -or- bottom|start
app:expandedTitleMargin
app:expandedTitleMarginBottom
app:expandedTitleMarginStart
app:expandedTitleMarginEnd

Zakładam, że używasz NoActionBar motyw, dlatego zacząłeś od TextView dla tytułu.

Oto twój układ, skonfigurowany do użycia CollapsingToolbarLayout tytuł:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="@dimen/detail_view_app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="@style/CollapsingToolbarLayoutExpandedTextStyle"
app:expandedTitleMarginBottom="64dp"
app:expandedTitleMarginStart="16dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<!--
set the expandedTitleMarginBottom to a value
that positions the expanded title above the rating bar
-->

<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />

<RatingBar
android:id="@+id/rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="16dp"
app:layout_collapseMode="parallax" />

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

Następnie w swoim kodzie ustaw tytuł na CollapsingToolbarLayout:

        CollapsingToolbarLayout collapsingToolbar =
(CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar_layout);
collapsingToolbar.setTitle("Title");