【问题标题】:Android Tv button is not selected未选择 Android 电视按钮
【发布时间】:2016-11-07 15:35:50
【问题描述】:

我遇到了显示布局问题。 相对布局@+id/media 放可见时不可见。他仍然在 Relativelayout @+id/media2 下,可以从 dpad 中选择,但仍然在 other 下。

如果零件和放 media2 第一和第二个媒体。当媒体可见,但不能选择 dpad 时。

有一定的顺序可以让media虽然先写在media2之上? 谢谢

布局

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/app_video_box"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#000"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/media"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:gravity="center_vertical|center_horizontal|center"
            android:layout_marginLeft="32dp"
            android:layout_marginRight="32dp"
            android:animateLayoutChanges="true"
            android:background="#e72a2a"
            android:id="@+id/relativeLayout">

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Back"
                android:id="@+id/button2"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/button"
                android:layout_toEndOf="@+id/button" />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Play"
                android:id="@+id/button" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Next"
                android:id="@+id/button3"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/button2"
                android:layout_toEndOf="@+id/button2" />

        </RelativeLayout>

        <SeekBar
            android:id="@+id/app_video_seekBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusable="true"
            android:layout_above="@+id/relativeLayout"
            android:layout_alignLeft="@+id/relativeLayout"
            android:layout_alignStart="@+id/relativeLayout"
            android:layout_alignRight="@+id/relativeLayout"
            android:layout_alignEnd="@+id/relativeLayout" />


    </RelativeLayout>
    <RelativeLayout
        android:id="@+id/media2"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <tcking.github.com.giraffeplayer.IjkVideoView
            android:id="@+id/video_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </RelativeLayout>

</RelativeLayout>

【问题讨论】:

  • 您需要为 media 和 media2 指定相对位置,就像您为其他控件所做的那样。
  • 你能给我更多的细节吗?

标签: android android-layout android-tv smart-tv


【解决方案1】:

您似乎正试图控制屏幕上不同项目的焦点。您可以专门为此使用 XML 标记:

android:nextFocusForward="@+id/media2"

android:nextFocusDown="@+id/media2"

您可以查看docs for keyboard navigation 了解更多信息。

【讨论】:

    【解决方案2】:

    在 Android TV 中,只有可聚焦的 ui 元素才会被选中。 通过 xml 属性或代码实现这一点。

    view.setFocusable(true)
    

    android:focusable="true".
    

    并为每个要转移焦点的ui元素设置规则。

    android:nextFocus{direction}="view_id".
    

    方向可以是向下、向上、向右或向左

    可聚焦的项目

    【讨论】:

      猜你喜欢
      • 2016-06-17
      • 1970-01-01
      • 2016-08-10
      • 1970-01-01
      • 2019-02-03
      • 2018-12-20
      • 1970-01-01
      • 2012-11-06
      • 1970-01-01
      相关资源
      最近更新 更多