2

I tried to combine leanback with xml, but I had some problem - padding the leanback row is different from padding other elements. How can I change padding to RowsSupportFragment? enter image description here

In xml

<RelativeLayout
        android:id="@+id/tags_container"
        android:layout_below="@+id/guidance_icon"
        android:visibility="gone"
        android:layout_width="match_parent"
        android:layout_height="50dp"/>

And in java code

RelativeLayout tags = view.findViewById(R.id.tags_container);
            ScreenshotFragment = FragmentScreenshots.newInstance(mFilm);
            getChildFragmentManager()
                    .beginTransaction()
                    .replace(tags.getId(), ScreenshotFragment)
                    .commit();

class FragmentScreenshots

public static class FragmentScreenshots extends RowsSupportFragment {
    private Film mFilm = null;

    public static FragmentScreenshots newInstance(Film film) {
        FragmentScreenshots fragment = new FragmentScreenshots();
        Bundle args = new Bundle();
        args.putSerializable(ActivityFilm.PARAM_FILM, film);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ListRowPresenter presenter = new CompatibleListRowPresenter(false, false, true);
        ArrayObjectAdapter mRowsAdapter = new ArrayObjectAdapter(presenter);
        List<AbstractCard> list = new ArrayList<>();
        setAdapter(mRowsAdapter);

        ...
        }
    }
}

1 Answer 1

3

I found where I can edit the padding on RowsSupportFragment.

In your activity theme add the item

<item name="rowHorizontalGridStyle">@style/CustomHorizontalGridView</item>

And in CustomHorizontalGridView u can edit padding

<style name="CustomHorizontalGridView">
    <item name="android:focusable">true</item>
    <item name="android:focusableInTouchMode">true</item>

    <item name="android:paddingStart">@dimen/your_padding</item>
    <item name="android:paddingEnd">@dimen/your_padding</item>

    <item name="android:paddingBottom">@dimen/lb_browse_item_vertical_spacing</item>
    <item name="android:paddingTop">@dimen/lb_browse_item_vertical_spacing</item>
    <item name="android:horizontalSpacing">@dimen/lb_browse_item_horizontal_spacing</item>
    <item name="android:verticalSpacing">@dimen/lb_browse_item_vertical_spacing</item>
    <item name="focusOutFront">true</item>
</style>
Sign up to request clarification or add additional context in comments.

1 Comment

If I can give you more than +1 , I would do it, thanks as lot! Just one minor thing though: there is a small mistake in the xml code HorizontalGridView should be CustomHorizontalGridView

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.