android-tv - 为 BrowseSupportFragment 膨胀新布局
问题描述
我想在我的 Android 电视应用程序上为我的 BrowseSupportFragment 增加新的自定义布局。我尝试了很多方法,但都没有成功。BrowseSupportFragment 的根布局是 lb_browse_fragment 我尝试使用相同的 Id 创建新文件并按如下方式对其进行膨胀,但出现错误。有人可以帮我处理这个案子吗?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/browse_dummy"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- BrowseFrameLayout serves as root of transition and manages switch between
left and right-->
<androidx.leanback.widget.BrowseFrameLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:descendantFocusability="afterDescendants"
android:id="@+id/browse_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.leanback.widget.BrowseRowsFrameLayout
android:id="@+id/browse_container_dock"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.leanback.widget.ScaleFrameLayout
android:id="@+id/scale_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.leanback.widget.BrowseRowsFrameLayout>
<!-- Padding needed for shadow -->
<FrameLayout
android:id="@+id/browse_headers_dock"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingEnd="50dp" />
</androidx.leanback.widget.BrowseFrameLayout>
我的 MainFragment 扩展了 BrowseSupportFragment :
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View view = inflater.inflate(R.layout.browse_fragment_costumized, container, false);
return view;
}
解决方案
BrowseSupportFragment在 onCreateView 中做了很多设置,包括确保处理过扫描并设置了很多引用。如果不调用 onCreateView,您将无法以有意义的方式使用此 Fragment,否则您将打破它在内部所做的所有假设。
如果您要大幅更改布局,则不应使用 BrowseSupportFragment。如果你只是需要改变一些小东西,你可以调用 super onCreateView 方法,然后修改返回的 View。
推荐阅读
- c++ - 重载运算符 [] 并且没有得到“需要左值作为赋值的左操作数”错误
- python - 从回调函数渲染数据表 - Dash
- loopbackjs - 如何在扩展“用户”模型的“用户”模型中删除电子邮件的唯一性检查?
- python - 为什么这个 Python 函数会在循环中中断?
- javascript - 使用 while/for 只读取两行输入
- aem - 如何在sightly/HTL中为类属性值添加作者/编辑模式条件。?
- java - 正则表达式以匹配多行中的字符串模式
- highcharts - yii2 : 来自数据库的动态 dosamigos HighCharts
- machine-learning - 重新加载腌制的 sklearn 管道时出现问题。未导入计数向量分析器功能
- c# - 如何检查特定名称是否参与对话,然后启用 true 如果不是 false?