我是 Android TV 应用程序开发的新手。
我的问题是打开侧边菜单时,我的一个或多个应用程序屏幕从右侧被切断。我尝试浏览Google 的 Android TV 文档,但找不到任何线索。
这是我的电视应用程序的显示/隐藏侧面菜单的代码:
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()
}
这是我对侧边菜单的设计:
<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" />
我将不胜感激有关此问题的任何线索。