5

我正在尝试使用 Android Lean back 库构建我的第一个 Amazon Fire TV 应用程序。我想将 BrowseFragment 自定义为如下图所示。

预期布局

我尝试如下设置自定义布局。

 @Override public View onInflateTitleView(LayoutInflater inflater, ViewGroup parent,
      Bundle savedInstanceState) {
    View title = inflater.inflate(R.layout.custom_title_view, parent, false);
    titleImageView = (AppCompatImageView) title.findViewById(R.id.title_content_thumbnail);
    return title;
  }

但生成的布局如下所示,带有透明的 TitleView,列表行显示在其下方。请提出一种更好的方法来使 UI 看起来与第一张图像相似。找不到任何可以实现这一点的东西。

在此处输入图像描述

4

1 回答 1

2

所以,我以某种方式解决了这个问题。我的activity_main.xml样子是这样的。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/default_background"
    android:orientation="vertical"
    >
  <fragment
      android:id="@+id/title_layout"
      android:name="com.kalpnik.vrdevotee.fragment.MainTitleFragment"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_alignParentTop="true"
      android:layout_weight="1"
      />
  <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="0dp"
      android:layout_below="@+id/title_layout"
      android:layout_weight="1"
      tools:deviceIds="tv"
      />
</LinearLayout>

FrameLayout我将加载一个从 扩展的片段BrowseFragment,所以这给了我必要的行。

在顶部,我正在加载MainTitleFragment扩展,Fragment布局如下所示。

片段主标题.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="#000000"
    android:orientation="horizontal"
    >
  <LinearLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="1"
      android:background="@color/icon_background"
      android:orientation="vertical"
      android:paddingTop="16dp"
      >
    <TextView
        android:id="@+id/title_content_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginHorizontal="16dp"
        tools:text=""
        android:textColor="@color/colorPrimaryDark"
        android:textSize="28sp"
        android:textStyle="bold"
        />
    <TextView
        android:id="@+id/title_content_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginHorizontal="16dp"
        android:layout_marginTop="16dp"
        android:ellipsize="end"
        android:text=""
        android:textSize="15sp"

        />
  </LinearLayout>
  <FrameLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="1"
      >

    <android.support.v7.widget.AppCompatImageView
        android:id="@+id/title_content_thumbnail"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        />
    <View
        android:layout_width="100dp"
        android:layout_height="match_parent"
        android:layout_gravity="left|start"
        android:background="@drawable/transparent_bg"
        />
    <View
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_gravity="bottom"
        android:background="@drawable/transparent_bg_bottom"
        />
  </FrameLayout>

</LinearLayout>

这对我有用。希望这可以帮助。

于 2019-07-21T09:07:46.237 回答