Max Yablonskyi
Max Yablonskyi

Reputation: 59

Add items before recyclerview

I have an activity with a recycler view. But I need to add an image before recycler view (like instagram stories before feed). How do I implement it?

my xml file

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:title="Locations"
            app:titleTextColor="@color/white" />

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/cropmap"
        tools:listitem="@layout/item_marker" />

    <ImageView
        android:id="@+id/cropmap"
        android:layout_width="match_parent"
        android:layout_height="168dp"
        android:background="@drawable/cropmap" />

        <ProgressBar
            android:id="@+id/main_progress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />

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

Thanks!

Upvotes: 1

Views: 201

Answers (3)

emilpmp
emilpmp

Reputation: 1736

The perfect way of doing this is to take advantage of "Item View type" in recyclerview. Basically what you should be doing is populating the image on top inside the recyclerview itself. The image will appear as the first item in recyclerview and other items will come subsequently. This can be implemented by using ItemViewType in recyclerview. Some useful resources can be found here and here

Upvotes: 1

miguelarc
miguelarc

Reputation: 800

Take advantage of the full potential of fragments. You can set a FrameLayout between your top bar and recyclerView, and then add a fragment there, or just simply use the <fragment> tag on your xml. For more info about flexible UI, please take a look in the Android documentation here.

Think of this fragment as your other section, like the Instagram example you just gave. There you can add what you want (ViewPager, HorizontalScrollView, etc), and be reflected when you inject the fragment in your layout.

Upvotes: 0

Raj
Raj

Reputation: 3001

<LinearLayout
    android:layout_width="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:weightSum="10">

    <ImageView
        android:id="@+id/cropmap"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@drawable/cropmap"
        android:layout_weight="3"  />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:scrollbars="vertical"
        tools:listitem="@layout/item_marker"
        android:layout_weight="7" />

 </Linearayout>


    <ProgressBar
        android:id="@+id/main_progress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

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

Upvotes: 0

Related Questions