如何在RecyclerView Android中修复第一行?

时间:2014-08-04 06:09:24

标签: 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"
        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());


        }
    }

0 个答案:

没有答案