3

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

我的列表.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());


        }
    }
4

0 回答 0