adsl9002 2023-07-25 14:50 采纳率: 46.2%
浏览 11

VerticalGridSupportFragment如何使用

尝试Leanback,能正常加载BrowseSupportFragment布局,

img


activity.main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.MainActivity">

</FrameLayout>

MainActivity.kt

import android.os.Bundle
import androidx.fragment.app.FragmentActivity
import com.example.griatest.R

class MainActivity : FragmentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        if (savedInstanceState == null) {
            supportFragmentManager.beginTransaction()
                .replace(R.id.main_fragment, MainFragment())
                .commit()
        }
    }
}

MainFragment.kt

import androidx.leanback.app.VerticalGridSupportFragment

class MainFragment : BrowseSupportFragment() {
}

但是改为加载VerticalGridSupportFragment布局就不正常,报错,应该怎么使用这种卡片布局

import androidx.leanback.app.VerticalGridSupportFragment

class MainFragment : VerticalGridSupportFragment() {
}

img

  • 写回答

2条回答 默认 最新

  • CSDN专家-sinJack 2023-07-25 15:11
    关注

    java.lang.NullPointerExcention: Attemot to inwoke wirtual method 'androdx.leanback widget JerticalGridPresente’
    看控制台的报错,空指针异常了。

    评论

报告相同问题?

问题事件

  • 创建了问题 7月25日

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错