简体   繁体   中英

Android Tv button is not selected

I encountered a problem with the display layout. Relativelayout @+id/media is not visible when you put visible. He remains under Relativelayout @+id/media2,is selectable from dpad but remains under the other.

if the parts and put media2 first and second media. When media is visible, but can not be selectable dpad.

there is a certain order to make the media though is written first be above the media2? Thank you

layout

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

It seems like you're trying to control the focus on different items on screen. You can use XML tags specifically for this:

android:nextFocusForward="@+id/media2"

android:nextFocusDown="@+id/media2"

You can look at the docs for keyboard navigation to learn more.

In Android TV, only ui elements gets selected only if they are focusable. Achieve this either through xml attributes or by code.

view.setFocusable(true)

or

android:focusable="true".

And set rules for each ui elements to whom the focus to be transferred.

android:nextFocus{direction}="view_id".

where direction could be down, top, right or left .

focusable items

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM