Android:网格项目未在第一行的SuperRecyclerView GridLayout中的第二项对齐

时间:2016-04-25 14:34:19

标签: android android-studio android-recyclerview sticky gridlayoutmanager

我有使用SuperRecyclerView的GridLayout和病态的标题它工作正常但它没有在第一行中排列第二项this,我怎样才能解决我的问题请帮助我的代码如下。

activity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white_color">

    <android.support.design.widget.CoordinatorLayout       xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="@color/white_color"
            android:fitsSystemWindows="true">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="48dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <LinearLayout
                    android:id="@+id/linearImageView"
                    android:layout_width="fill_parent"
                    android:layout_height="160dp"
                    android:layout_marginBottom="50dp"
                    android:layout_marginTop="50dp"
                    android:descendantFocusability="beforeDescendants"
                    android:focusableInTouchMode="true"
                    android:orientation="vertical"
                    android:padding="0dp">

                    <android.support.v4.view.ViewPager
                        android:id="@+id/mViewPager"
                        android:layout_width="match_parent"
                        android:layout_height="160dp"
                        android:overScrollMode="never" />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/container_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <include
                        android:id="@+id/toolbar"
                        layout="@layout/toolbar" />

                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/gray_hint_border_color" />

            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>
    <com.malinskiy.superrecyclerview.SuperRecyclerView
            android:id="@+id/mRecycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:layout_empty="@layout/emptyview"
            app:mainLayoutId="@layout/layout_recyclerview_verticalscroll"
            app:recyclerClipToPadding="false"
            app:scrollbarStyle="outsideOverlay" />
</android.support.design.widget.CoordinatorLayout>

    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="com.vrin.sga.ui.FragmentDrawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>

Home.java

mRecycler = (SuperRecyclerView) findViewById(R.id.mRecycler);
//        mRecycler.setLayoutManager(new LinearLayoutManager(mActivity));
        mRecycler.setLayoutManager(new GridLayoutManager(mActivity, 2));

        mListBeanArrayList = new ArrayList<>();

        mAdapter = new DashboardAdaper(mActivity, mListBeanArrayList);
        fillData();
        mAdapter.setHasStableIds(true);
        mRecycler.setAdapter(mAdapter);
        top = new StickyHeadersBuilder()
                .setAdapter(mAdapter)
                .setRecyclerView(mRecycler.getRecyclerView())
                .setStickyHeadersAdapter(new InitialHeaderAdapter(mListBeanArrayList,mActivity))
                .build();

        mRecycler.addItemDecoration(top);


private void fillData() {
        productListBean = new ProductListBean();
        productListBean.header = ("DEALS OF THE WEEK");
        productListBean.name = ("Pienaple Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("DEALS OF THE WEEK");
        productListBean.name = ("Chocolate Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("DEALS OF THE WEEK");
        productListBean.name = ("Pienaple Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("DEALS OF THE WEEK");
        productListBean.name = ("Chocolate Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("DEALS OF THE WEEK");
        productListBean.name = ("Pienaple Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("DEALS OF THE WEEK");
        productListBean.name = ("Chocolate Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("DEALS OF THE WEEK");
        productListBean.name = ("Pienaple Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("DEALS OF THE WEEK");
        productListBean.name = ("Chocolate Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("DEALS OF THE WEEK");
        productListBean.name = ("Pienaple Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("DEALS OF THE WEEK");
        productListBean.name = ("Chocolate Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("NEW GIFTS");
        productListBean.name = ("Chocolate Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("NEW GIFTS");
        productListBean.name = ("Pienaple Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("NEW GIFTS");
        productListBean.name = ("Chocolate Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("NEW GIFTS");
        productListBean.name = ("Pienaple Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("NEW GIFTS");
        productListBean.name = ("Chocolate Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("NEW GIFTS");
        productListBean.name = ("Pienaple Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);

        productListBean = new ProductListBean();
        productListBean.header = ("NEW GIFTS");
        productListBean.name = ("Chocolate Cake");
        productListBean.imgProduct = R.drawable.ic_launcher1;
        mListBeanArrayList.add(productListBean);
    }

0 个答案:

没有答案