我有使用带有病态标题的 SuperRecyclerView 的 GridLayout 它工作正常,但它与第一行的第二个项目不对齐,我该如何解决我的问题请帮助我,如下所示。
活动.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>
主页.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);
}