简体   繁体   English

想要为 Android 电视创建自定义视图

[英]Want to create a Custom View for Android TV

I have already gone through several different available Questions related to this, but not found very much useful.我已经经历了几个与此相关的不同可用问题,但没有发现非常有用。

  1. Android TV. Android 电视。 Adding custom views to VerticalGridFragment 向 VerticalGridFragment 添加自定义视图

How I can customize the View Inside the RowSupportFragment or Like is there any other way to achieve the same.我如何自定义 RowSupportFragment 内部的 View 或 Like 是否有任何其他方法可以实现相同的目的。

这是需要开发的Layout

Are you using Presenter right?你用的Presenter对吗? I think you need to use different types same way RecyclerView and Adapters has the itemViewType and transform your BaseCardView based on some rule, it could be the position or the type of it.我认为您需要使用不同的类型,同样RecyclerViewAdapters具有itemViewType并根据某些规则转换您的BaseCardView ,它可能是 position 或它的type I manage to do something like this for a row with the "View All" last card:我设法用“查看全部”最后一张卡片连续做这样的事情:

// 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
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM