更改 RowsSupportFragment 上的填充
Change padding on RowsSupportFragment
我尝试将 leanback 与 xml 结合使用,但我遇到了一些问题 - 填充 leanback 行与填充其他元素不同。如何将填充更改为 RowsSupportFragment?
在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"/>
并且在java代码中
RelativeLayout tags = view.findViewById(R.id.tags_container);
ScreenshotFragment = FragmentScreenshots.newInstance(mFilm);
getChildFragmentManager()
.beginTransaction()
.replace(tags.getId(), ScreenshotFragment)
.commit();
class 片段截图
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);
...
}
}
}
我找到了可以在 RowsSupportFragment 上编辑填充的位置。
在您的 activity 主题中添加项目
<item name="rowHorizontalGridStyle">@style/CustomHorizontalGridView</item>
并且在 CustomHorizontalGridView 中你可以编辑 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>
我尝试将 leanback 与 xml 结合使用,但我遇到了一些问题 - 填充 leanback 行与填充其他元素不同。如何将填充更改为 RowsSupportFragment?
在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"/>
并且在java代码中
RelativeLayout tags = view.findViewById(R.id.tags_container);
ScreenshotFragment = FragmentScreenshots.newInstance(mFilm);
getChildFragmentManager()
.beginTransaction()
.replace(tags.getId(), ScreenshotFragment)
.commit();
class 片段截图
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);
...
}
}
}
我找到了可以在 RowsSupportFragment 上编辑填充的位置。
在您的 activity 主题中添加项目
<item name="rowHorizontalGridStyle">@style/CustomHorizontalGridView</item>
并且在 CustomHorizontalGridView 中你可以编辑 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>