Android 电视 Leanback

标签 android android-fragments android-tv leanback

layout I am trying to achieve

我是 Android TV 开发新手。我不知道该使用哪种类型的 fragment 。我想要两个类似于上面屏幕截图的实现布局作为 jiocinema。不知何故,我使用 Activity 布局内的两个 xml fragment 实现了它。第二个 fragment 在点击 API 后加载屏幕截图,因此它会在一段时间后加载。从上面的屏幕截图中可以看出,我希望布局分为两部分。顶部的部分包含详细信息和一些按钮,底部的部分是该电影的屏幕截图列表。

就我而言,问题是,底部列表部分将焦点放在加载此特定屏幕上,然后按下向上按钮或任何按钮,它永远不会失去焦点,也永远不会进入顶部部分。 注意:下面的 fragment 异步加载,因为它会调用屏幕截图网址的 api

可能我没有为这个特定的布局使用正确的 fragment 。有人可以指出我的代码或帮助我决定使用什么来实现这种布局吗?因为它可以实现,但导航是主要的。

代码

Activity 布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/photo_label_box">
    <fragment
        android:id="@+id/detail_layout"
        android:layout_width="match_parent"
        android:name="com.DetailsActivityGame$Detalfragment"
        android:layout_height="200dp"></fragment>
    <fragment
        android:id="@+id/row_layout"
        android:layout_width="match_parent"
        android:layout_below="@+id/detail_layout"
        android:name="com.DetailsActivityGame$SampleFragmentC"
        android:layout_height="wrap_content"></fragment>
</RelativeLayout>

谢谢

最佳答案

尝试使用 V4 支持 fragment 中的 RowSupportFragment 来获得所需的输出。

将布局分为两部分布局,其中包含按钮、说明和下方滚动布局(由 RowSupportFragment 表示)

//----------------------detail_layout

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/leader_background">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/main_layout"
  //your own layout design for buttons and description
</RelativeLayout>
<fragment
    android:name="FragmentScreenshots"
    android:id="@+id/screenshot_fragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />
    </LinearLayout>

//----------------详细 fragment --------------------

public static class Detailfragment extends Fragment {
    public  Detailfragment(){ }

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.detail_layout, container, false);
        //————————your own implementation—————————————————————————
        return view;
     }
     public static class FragmentScreenshots extends RowsSupportFragment {
         private ArrayObjectAdapter mRowsAdapter = null;
          public FragmentScreenshots() {
            mRowsAdapter = new ArrayObjectAdapter(new ShadowRowPresenterSelector());
            setAdapter(mRowsAdapter);
           }

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
          //———————Provide data accordinally———————————
             List<ScreenshotItem> list;

             // Add a Related items row
            ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(
                    new ScreenshotCardPresenter(getActivity()));
            for (ScreenshotItem s:list)
            {
                listRowAdapter.add(s);
            }
            HeaderItem header = new HeaderItem("Screenshots");
            mRowsAdapter.add(new ListRow(header, listRowAdapter));
            setAdapter(mRowsAdapter);

            setOnItemViewClickedListener(new OnItemViewClickedListener() {
                @Override
                public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
                    if (item instanceof ScreenshotItem) {
                                                  }
                    else{
                                                }
                }
            });

            setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
                @Override
                public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {

                }
            });
        }

        @Override
        public void setExpand(boolean expand) {
            super.setExpand(true);
        }

        @Override
        public void setOnItemViewClickedListener(BaseOnItemViewClickedListener listener) {
            super.setOnItemViewClickedListener(listener);
        }

        @Override
        public void setOnItemViewSelectedListener(BaseOnItemViewSelectedListener listener) {
            super.setOnItemViewSelectedListener(listener);
        }
    }}

关于Android 电视 Leanback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53116488/

相关文章:

android - 卡在 Android TV/Fire TV 的 Charles 代理证书安装中

java - 在android中创建菜单/子菜单

android - 在 ViewPager android 中锁定页面 fragment

安卓牛轧糖 : Why do checkboxes on Fragment have incomplete state when selected programmatically (but look fine on Lollipop)

android-tv - 在 Android TV 上安装证书

android - 清理应用程序数据不起作用

android - 与服务器同步

android - 重用从 Realm 数据库中删除的对象

android - Kotlin 数组中的所有项始终包含最后一项

android - 具有向后兼容性 android 的抽屉导航