4

Hi am try to create on demo there i want to fixed first row from RecyclerView, i have creted one list from that but i do't know how to fixed first row.

Mylist.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        tools:context="com.hmkcode.android.recyclerview.MainActivity" >



        <android.support.v7.widget.RecyclerView
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".MainActivity"
        />
    </RelativeLayout>

MainActivity.java

    import android.support.v7.widget.DefaultItemAnimator;
    import android.support.v7.widget.LinearLayoutManager;
    import android.support.v7.widget.RecyclerView;
    import android.app.Activity;
    import android.os.Bundle;

    public class MainActivity extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);

            ItemData itemsData[] = { new ItemData("Help", R.drawable.help),
                    new ItemData("Delete", R.drawable.content_discard),
                    new ItemData("Cloud", R.drawable.collections_cloud),
                    new ItemData("Favorite", R.drawable.rating_favorite),
                    new ItemData("Like", R.drawable.rating_good),
                    new ItemData("Rating", R.drawable.rating_important),
                    new ItemData("Help", R.drawable.help),
                    new ItemData("Delete", R.drawable.content_discard),
                    new ItemData("Cloud", R.drawable.collections_cloud),
                    new ItemData("Favorite", R.drawable.rating_favorite),
                    new ItemData("Like", R.drawable.rating_good),
                    new ItemData("Rating", R.drawable.rating_important),
                    new ItemData("Help", R.drawable.help),
                    new ItemData("Delete", R.drawable.content_discard),
                    new ItemData("Cloud", R.drawable.collections_cloud),
                    new ItemData("Favorite", R.drawable.rating_favorite),
                    new ItemData("Like", R.drawable.rating_good),
                    new ItemData("Rating", R.drawable.rating_important) };

            recyclerView.setLayoutManager(new LinearLayoutManager(this));

            MyAdapter mAdapter = new MyAdapter(itemsData);
            recyclerView.setAdapter(mAdapter);
            recyclerView.setItemAnimator(new DefaultItemAnimator());


        }
    }
matiash
  • 54,791
  • 16
  • 125
  • 154
Amit Prajapati
  • 13,525
  • 8
  • 62
  • 84
  • Do you want just first row fixed? Why not use http://developer.android.com/reference/android/widget/ListView.html#addHeaderView%28android.view.View,%20java.lang.Object,%20boolean%29 in that case? – sandrstar Aug 08 '14 at 06:13
  • 1
    yes you are right Listview provide addHeaderView meathod but RecyclerView not.. so my Question how to fix that first row in RecyclerView – Amit Prajapati Aug 08 '14 at 06:25
  • Actually, addHeaderView() provides not fixed header (it scrolls with the view). For fixed header you don't need to do anything with the list, just update layout as discussed here http://stackoverflow.com/questions/4274519/android-how-to-avoid-header-from-scrolling-in-listview-android . – sandrstar Aug 08 '14 at 10:10

0 Answers0