Java 如何修复RecyclerView Android中的第一行?

Java 如何修复RecyclerView Android中的第一行?,java,android,android-recyclerview,Java,Android,Android Recyclerview,嗨,我尝试在演示中创建,我想修复RecyclerView中的第一行,我已经推荐了其中的一个列表,但我不知道如何修复第一行 Mylist.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent

嗨,我尝试在演示中创建,我想修复RecyclerView中的第一行,我已经推荐了其中的一个列表,但我不知道如何修复第一行

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>

你想修第一排吗?为什么不在这种情况下使用?是的,您是对的,Listview提供addHeaderView方法,但RecyclerView不提供。。所以我的问题是如何修复RecycleService中的第一行实际上,addHeaderView()提供了不固定的标题(它随视图滚动)。对于固定标题,您不需要对列表执行任何操作,只需按照此处讨论的方式更新布局即可。
    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());


        }
    }