【问题标题】:Want to create a Custom View for Android TV想要为 Android TV 创建自定义视图
【发布时间】:2020-12-22 16:03:21
【问题描述】:

我已经完成了几个与此相关的不同可用问题, 但发现不是很有用。

  1. Android TV. Adding custom views to VerticalGridFragment

如何在 RowSupportFragment 或 Like 中自定义视图是否有其他方法可以实现相同的效果。

【问题讨论】:

    标签: android android-layout customization android-tv leanback


    【解决方案1】:

    您使用的是Presenter 对吗?我认为您需要以相同的方式使用不同的类型RecyclerViewAdapters 具有itemViewType 并根据某些规则转换您的BaseCardView,它可能是它的位置或type。我设法用“查看全部”最后一张卡片连续做这样的事情:

    // This is just a simple FrameLayout with an ImageView or a TextView...
    
    var firstItem: Any? = null
    
    class PortraitTitleCardPresenter(context: Context) :
        AbstractCardPresenter<BaseCardView>(context) {
    
    
        override fun onCreateView(): BaseCardView {
            val cardView = BaseCardView(context, null, R.style.BaseCard)
            cardView.isFocusable = true
            cardView.addView(LayoutInflater.from(context).inflate(R.layout.item_home, null))
    
            return cardView
        }
    
        override fun onBindViewHolder(card: Any, cardView: BaseCardView) {
            if(firstItem == null) {
                firstItem = card
                //Do something with firstItem...
            }
    
            if (card is ItemTitleType) {
                cardView.image.visibility = View.VISIBLE
                cardView.viewAll.visibility = View.GONE
                
                Glide.with(context)
                    .load(card.imageUrl)
                    .centerCrop()
                    .apply(RequestOptions().placeholder(R.drawable.ic_wm_black)
                        .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                    ).into(cardView.image)
            }
    
            if (card is ViewAllType) {
                cardView.image.visibility = View.GONE
                cardView.viewAll.visibility = View.VISIBLE
            }
        }
    }
    

    【讨论】:

    • 这不符合设计要求。并使用 Recyclerview 适配器,它显示出一个非常滞后的问题。
    • 我没有提到使用 RecyclerView。我确实提到过使用 Presenter 并在那里添加一些行为来根据该行为绘制一个或另一个图块。
    猜你喜欢
    • 2012-07-25
    • 2018-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-07
    • 2020-08-20
    相关资源
    最近更新 更多