How to make android.support.v7.widget.Toolbar stay constantly above? With this code, it is duplicated through each news item:

 <?xml version="1.0" encoding="utf-8"?> <FrameLayout 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="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?actionBarSize" android:background="?attr/colorPrimary" android:elevation="4dp" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:theme="@style/ToolbarTheme" /> <LinearLayout android:id="@+id/feed_item" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:orientation="vertical" android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:paddingRight="?android:attr/listPreferredItemPaddingRight"> <TextView android:id="@+id/feed_item_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/margin" android:textColor="@color/text_dark" android:textAppearance="@style/TextAppearance.AppCompat.Title" /> <TextView android:id="@+id/feed_item_description" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@color/text_medium" android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> <TextView android:id="@+id/feed_item_date" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/margin" android:textColor="@color/text_light" android:gravity="end" android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="match_parent" android:background="?android:attr/selectableItemBackground" /> </FrameLayout> 
  • This is not a code, but a markup. How is it used? Not enough information to understand the problem - pavlofff
  • one
    Most likely, you apply this markup to each news item, even in names it is written *** _ item. Try to bring the toolbar into a container that displays all these items - Garf1eld
  • I use this markup to display a list of news. That is, the title, overview and date are indicated. At the top I want to place the toolbar. - Sergey Tikhomirov
  • @SergeyTikhomirov code show how you use it - anber

1 answer 1

Maybe so:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" > <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_alignParentTop="true" android:layout_width="match_parent" android:layout_height="?actionBarSize" android:background="?attr/colorPrimary" android:elevation="4dp" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:theme="@style/ToolbarTheme" /> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/feed_item" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:orientation="vertical" android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:paddingRight="?android:attr/listPreferredItemPaddingRight"> <TextView android:id="@+id/feed_item_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/margin" android:textColor="@color/text_dark" android:textAppearance="@style/TextAppearance.AppCompat.Title" /> <TextView android:id="@+id/feed_item_description" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@color/text_medium" android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> <TextView android:id="@+id/feed_item_date" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/margin" android:textColor="@color/text_light" android:gravity="end" android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="match_parent" android:background="?android:attr/selectableItemBackground" /> </FrameLayout> </RelativeLayout> 
  • Even for FrameLayout, you can add a property: android: layout_below = "@ id / toolbar" - konstantin