首页 > 解决方案 > 当焦点在android TV中从一个行移动到另一个行时,有没有办法停止RowsSupportFragment中行的垂直移动?

问题描述

我一直试图停止 RowsSupportFragment 中的垂直移动。我有两行,我希望它们一直显示在固定位置。

在 android TV 中,只要焦点在 Rows 中垂直移动,下一行就会向上移动并离开其原始位置。我希望它垂直固定。

如果有什么办法可以帮我解决这个问题吗?

标签: androidandroid-tvleanback

解决方案


你想保持焦点固定吗?

以下代码将使焦点位置固定到第一行:

    // Item alignment affects focused row that isn't the last.
    getVerticalGridView().setItemAlignmentOffset(0);
    getVerticalGridView().setItemAlignmentOffsetPercent(0);
    // Push rows to the top.
    getVerticalGridView().setWindowAlignmentOffset(0);
    getVerticalGridView().setWindowAlignmentOffsetPercent(0);

getVerticalGridView().setWindowAlignment(VerticalGridView.WINDOW_ALIGN_LOW_EDGE);

查看以下链接了解更多详情: https ://developer.android.com/reference/android/support/v17/leanback/widget/VerticalGridView


推荐阅读