【问题标题】:Add custom view to AndroidTV's Leanback RowsSupportFragment?向 AndroidTV 的 Leanback RowsSupportFragment 添加自定义视图?
【发布时间】:2019-01-22 17:10:35
【问题描述】:

是否可以在 RowsSupportFragment 中的行上方和行之间添加一些视图?

【问题讨论】:

  • 你检查过这个SO post吗?
  • 嗨。我的问题是关于 Android TV 的 Leanback 库的特定 RowsFragment

标签: user-interface android-tv leanback


【解决方案1】:

可以通过在onViewCreated方法中将视图添加到VerticalGridView的父FrameLayout来添加行上方的任何视图。要为此视图留出空间,请为 verticalGridView.windowAlignmentOffsetPercent 设置适当的值:

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        (view.parent as? FrameLayout)?.run {
            val myView = LayoutInflater.from(context).inflate(R.layout.my_view_to_add, this, false)
            addView(myView)
        }
        verticalGridView?.let {
            it.windowAlignmentOffsetPercent = 30.0f
        }
    }

这个添加的视图是静态的,当焦点下降时不会滚动出来。

在行之间似乎除了 ItemDecorator 没有办法添加任何东西,因为 VerticalGridView 是 RecyclerView 的后代

【讨论】:

    猜你喜欢
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多