lucasr / twoway-view

[DEPRECATED] RecyclerView made simple
5.23k stars 1.02k forks source link

Items appear too late when have bottom padding #219

Open Deepscorn opened 9 years ago

Deepscorn commented 9 years ago

Having this layout:

<FrameLayout
    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/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:ignore="MergeRootFrame">

    <org.lucasr.twowayview.widget.TwoWayView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        style="@style/TwoWayView"
        app:twowayview_layoutManager="SpannableGridLayoutManager"
        app:twowayview_numColumns="58"
        app:twowayview_numRows="35"
        android:paddingBottom="@dimen/info_block_height"
        android:clipToPadding="false"/>
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/info_block_height"
        android:layout_gravity="bottom">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="AAAAAAAAAAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAA"
            />
    </FrameLayout>
</FrameLayout>

When scrolling content up items appear too late from below. I think this is due to padding. The main idea of bottom padding with clipToPadding="false" is to show bottom block (with TextView) when finished scrolling down with fade in. Another bug is the thing, that having these tiles:

private Tile[] tiles = new Tile[] {
            new Tile(39, 20),
            new Tile(19, 10),
            new Tile(19, 10),
            new Tile(29, 15),
            new Tile(29, 15)
    }; 

In onBindViewHolder(holder, position) in adapter:

final SpannableGridLayoutManager.LayoutParams lp =
                    (SpannableGridLayoutManager.LayoutParams) itemView.getLayoutParams();

            final int colSpan = tiles[position].width;
            final int rowSpan = tiles[position].height;

            if (lp.rowSpan != rowSpan || lp.colSpan != colSpan) {
                lp.rowSpan = rowSpan;
                lp.colSpan = colSpan;
                itemView.setLayoutParams(lp);
            }

Tiles positioned correctly, but I see a gap on the right side of the screen in both landscape and portrait orientation, that's my styles.xml for them both:

<style name="TwoWayView" parent="TwoWayViewBase">
        <item name="android:orientation">vertical</item>
        <item name="android:scrollbars">vertical</item>
    </style>

<style name="TwoWayViewBase">
        <item name="android:background">#999999</item>
    </style>
KoMinkyu commented 9 years ago

Try adding an item decoration at the bottom.

implement decoration.

class BottomSpaceDecoration extends ItemDecoration {
    private final LayoutManager mLayoutManager;
    private final int mHeightSize;

    public BottomSpaceDecoration(LayoutManager layoutManager, int heightSize) {
        mLayoutManager = layoutManager;
        mHeightSize = heightSize;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView recyclerView, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, recyclerView, state);

        int itemPosition = recyclerView.getChildAdapterPosition(view);

        if (itemPosition == mLayoutManager.getItemCount() - 1) {
            outRect.bottom = mHeightSize;
        }
    }
}

and apply decoration like this.

int heightSize = mContext.getResources().getDimension(R.dimen.bottom_padding_size);
mTwoWayView.addItemDecoration(new BottomSpaceDecoration(mTwoWayView.getLayoutManager(), heightSize));