how to always show headers in RowsFragment

这一生的挚爱 提交于 2019-12-04 04:36:28

As Mayur Kaul already mentioned, u just need to call

mRowsFragment.setExpand(true)

But in this case everytime when onAttachedToWindow(...) method would be called (see android.support.v17.leanback.app.RowsFragment - ItemBridgeAdapter.AdapterListener mBridgeAdapterListener), your header titles anyway would be hidden.

So final solution, witch worked for me it's just simply override setExpand() method in your RowsFragment implementation like below:

@Override
    public void setExpand(boolean expand) {
        super.setExpand(true);
    }

For those who are facing a similar problem, i finally managed to find a hack which will give the desired results. But for that you might need to get the source of BrowseSupportFragment or in Sofa and modify the following line of code. I know its a bit of hack, but it get's the desired output.

For BrowseFragment: Notice the mRowsFragment.setExpand(true)

private void showHeaders(boolean show) {
        if (DEBUG) Log.v(TAG, "showHeaders " + show);
        mHeadersFragment.setHeadersEnabled(show);
        setHeadersOnScreen(show);
        setRowsAlignedLeft(!show);
        if (mRowsFragment != null) {
            mRowsFragment.setExpand(true);
        } else if (mCurrentFragment != null && mCurrentFragment instanceof RowsFragment) {
            ((RowsFragment) mCurrentFragment).setExpand(true);
        }
    }

and same goes for the BrowseSupportFragment as well

private void showHeaders(boolean show) {
        if (DEBUG) Log.v(TAG, "showHeaders " + show);
        mHeadersSupportFragment.setHeadersEnabled(show);
        setHeadersOnScreen(show);
        setRowsAlignedLeft(!show);
        if (mRowsSupportFragment != null) {
            mRowsSupportFragment.setExpand(true);
        } else if (mCurrentFragment != null && mCurrentFragment instanceof RowsSupportFragment) {
            ((RowsSupportFragment) mCurrentFragment).setExpand(true);
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!