【问题标题】:Customize extended view(Fragment)自定义扩展视图(片段)
【发布时间】:2023-02-02 10:47:59
【问题描述】:

我在我的项目中使用了一个扩展 Leanback 库的 BrowseSupportFragment 的片段

顺便说一下,BrowseSupportFragment 的默认设置是 ListRow,每当更改类别标题时,我想以 VerticalGrid 形式而不是 Row 形式显示我的数据。

<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" >


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

此处显示的布局设置已在库中完成。

我可以在这种情况下修改这个布局形状吗?

或者我应该使用其他方式而不使用它吗?

【问题讨论】:

  • 您是否尝试过使用VerticalGridSupportFragment
  • 怪我这么晚才检查你的答案。。想了很久,通过配置两个VerticalGridFragments的方法做了一个类似的构图。我的错误是追求太简单了。谢谢回复
  • 没问题!如果您认为这可能对其他人有帮助,您可以将您的实施添加为答案。

标签: android android-fragments android-tv leanback


【解决方案1】:

我是这个问题的作者。我找到了这个问题的答案。如果您需要它,请随时使用它

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">


<androidx.fragment.app.FragmentContainerView
    android:id="@+id/header"
    android:name="com.your.package.YourFragmentHeader"
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:layout_marginStart="50dp" />

<androidx.fragment.app.FragmentContainerView
    android:id="@+id/fragmentContainerView"
    android:name="com.your.package.YourFragmentRight"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_toRightOf="@+id/header"
    />

布局就是这样实现的

MainFragment mainFragment = new MainFragment(categoryID);
    FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
    FragmentTransaction fragmentTransaction =
            fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.fragmentContainerView, mainFragment);
    fragmentTransaction.commit();

您可以通过编程方式将 Fragment 呈现为分组列表的动态网格,例如 BrowseSupportFragment 。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多