我正在使用Leanback库在示例代码中显示节目的详细信息。我用DetailsSupportFragment扩展了我的片段,并使用Presenter显示了细节。 我发现的问题是,当广告内容描述行超过2条时,通过按DPad向下按钮,光标移动正确地向下移动到了下一行,但是如果小于或等于2,光标将移至右边的内容(在我的图标中案件)。
这是我的示例代码:
class MyDetailsFragment : DetailsSupportFragment() {
private var mySelector: ClassPresenterSelector? = null
private var myRow: DetailsOverviewRow? = null
private var myAdapter: SparseArrayObjectAdapter? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
/// some code to load data///
var myPresenter = CustomFullWidthDetailsOverviewRowPresenter(myData, CustomPresenter(), DetailsOverviewLogoPresenter()) ;
mySelector?.addClassPresenter(DetailsOverviewRow::class.java, myPresenter)
myRow = DetailsOverviewRow(myData.data)
myAdapter.set(1, myRow)
/// other code
}
}
//Custom Presenter which sets title and description
class CustomPresenter : Presenter() {
override fun onCreateViewHolder(parent: ViewGroup): CbsAbstractDetailsDescriptionPresenter.ViewHolder {
/// returns view holder
return ViewHolder(v)
}
override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
// setting views here
}
}
class CustomFullWidthDetailsOverviewRowPresenter(myData: MyDataType, myPresenter: Presenter, logoPresenter: DetailsOverviewLogoPresenter): FullWidthDetailsOverviewRowPresenter {
override fun onLayoutOverviewFrame(viewHolder: FullWidthDetailsOverviewRowPresenter.ViewHolder,
oldState: Int, logoChanged: Boolean) {
// some code //
}
}
注意:我没有任何代码来处理DPad按钮事件。只需使用ScrollingMovementMethod()设置滚动运动即可。