0

I am new to Android TV apps development.

My issue is I have one or more of app's screens cut off from the right when open the side menu. I tried going through Google's Android TV Documentation but couldn't find a clue on it.

Here you can see attached image. enter image description here

Here is my code for show/hide side menu for my TV app:

private fun showSideMenu() {
    val sideMenuWidth = mSideMenuView.width
    mSideMenuAnimator = ObjectAnimator.ofFloat(mSideMenuView, "translationX", 0f)
    mSideMenuAnimator?.addListener(object : Animator.AnimatorListener {
        override fun onAnimationStart(animation: Animator?) {
            mSideMenuAnimator = null

            mSideMenuView.visibility = View.VISIBLE

            hideMenuText()
            mSideMenuView.requestFocus()
            mContainer.clearFocus()
        }

        override fun onAnimationEnd(animation: Animator?) {
        }

        override fun onAnimationRepeat(animation: Animator?) {
        }

        override fun onAnimationCancel(animation: Animator?) {
        }
    })
    mSideMenuAnimator?.duration = SIDE_MENU_ANIMATION_DURATION_MILLIS

    val containerAnimator = ObjectAnimator.ofFloat(mContainer, "translationX", sideMenuWidth * 1f)
    containerAnimator.duration = SIDE_MENU_ANIMATION_DURATION_MILLIS

    val animatorSet = AnimatorSet()
    animatorSet.play(mSideMenuAnimator).with(containerAnimator)
    animatorSet.start()
}

private fun hideSideMenu() {
    val sideMenuWidth = mSideMenuView.width
    mSideMenuAnimator = ObjectAnimator.ofFloat(mSideMenuView, "translationX", -sideMenuWidth * 1f)
    mSideMenuAnimator?.addListener(object : Animator.AnimatorListener {
        override fun onAnimationStart(animation: Animator?) {
            mSideMenuView.clearFocus()
            mContainer.requestFocus()
        }

        override fun onAnimationEnd(animation: Animator?) {
            mSideMenuAnimator = null

            mSideMenuView.visibility = View.INVISIBLE

            // Give focus control to current fragment
            mCurrentFragment?.onReceiveFocus()

            showMenuText()
        }

        override fun onAnimationRepeat(animation: Animator?) {
        }

        override fun onAnimationCancel(animation: Animator?) {
        }
    })
    mSideMenuAnimator?.duration = SIDE_MENU_ANIMATION_DURATION_MILLIS

    val containerAnimator = ObjectAnimator.ofFloat(mContainer, "translationX", 0f)
    containerAnimator.duration = SIDE_MENU_ANIMATION_DURATION_MILLIS

    val animatorSet = AnimatorSet()
    animatorSet.play(mSideMenuAnimator).with(containerAnimator)
    animatorSet.start()
}

Here is my design for the side menu:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">

<com.myapp.widget.SideMenuView
    android:id="@+id/view_side_menu"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:translationX="-220dp"
    android:visibility="invisible" />

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<TextView
    android:id="@+id/text_menu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentTop="true"
    android:layout_marginEnd="25dp"
    android:layout_marginTop="25dp"
    android:drawablePadding="4dp"
    android:background="@drawable/background_side_menu_indicator"
    android:drawableEnd="@drawable/icon_side_menu"
    android:focusable="false"
    android:text="MENU"
    app:primaryForegroundColor="false"
    style="@style/Text.SideMenuIndicator"
    tools:ignore="RelativeOverlap" />

I would appreciate any clue about this issue.

blueware
  • 5,205
  • 1
  • 40
  • 60

0 Answers0