【问题标题】:Change zoom of selected item for browsefragment in android tv在android tv中更改browsefragment的选定项目的缩放
【发布时间】:2015-11-10 16:00:49
【问题描述】:

我想为电视元素的 BrowseFragment 更改所选元素的缩放值。 是否可以?还是在browsefragment中硬编码的zoom os?

【问题讨论】:

  • 运气好吗??你做完了吗?
  • 我已经完成了..我会分享答案。
  • @MuhammadAdil 我需要类似的实现。你能分享你的代码吗?
  • 当然,我会将我所做的代码公开回购,以便其他人可以从中受益。

标签: android menuitem selected television leanback


【解决方案1】:

以下是更改卡片缩放系数的方法。在您的 MainFragment/RowsFragment 中,您必须使用 ListRowPresenter。你可以这样初始化它。

ListRowPresenter presenter= new ListRowPresenter(FocusHighlight.ZOOM_FACTOR_LARGE,true);

您可以在此处更改 FocusHighlight Factor,您会发现许多其他值,或者您可以根据您的要求选择任何值。以下是这些值。

ZOOM_FACTOR_MEDIUM , ZOOM_FACTOR_SMALL , ZOOM_FACTOR_XSMALL , ZOOM_FACTOR_NONE

如果您在第二个参数中传递 false,那么您可以移除所有网格上的暗光效果。你可以随便玩玩。这里有一些你可以使用的其他可能的功能

    presenter.setShadowEnabled(false);
    presenter.enableChildRoundedCorners(false);
    presenter.setSelectEffectEnabled(false);
    presenter.setKeepChildForeground(false);

这些在库中默认为 true

如果您想自定义leanback 的RowsFragmentBrowseFragment 的设计,那么只需获取它的XML 文件,您就可以尝试其设计。你可以把你自己的实现。这只是一个想法,您还可以自定义其他leanback片段。

这里是RowsFragment的布局我已经改变了一些颜色以便你理解请将它保存在res目录下的布局中,名称为“lb_rows_fragment.xml”,不要忘记给它命名,正如我所说的。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
    android:id="@+id/descriptions_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/main_screen_prog_desc_height"
    >

    <RelativeLayout
        android:id="@+id/description_parent_view"
        android:layout_width="@dimen/main_screen_prog_desc_width"
        android:layout_height="wrap_content"
        >
<!--you can add description etc here or any other stuff. whatever you like. -->
</RelativeLayout>

<android.support.v17.leanback.widget.ScaleFrameLayout
    android:id="@+id/scale_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/descriptions_layout"
    android:background="#fff"
    android:layout_marginRight="170dp">

    <android.support.v17.leanback.widget.VerticalGridView
        android:id="@+id/container_list"
        style="?attr/rowsVerticalGridStyle"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#45f"
        android:clipToPadding="false"/>

</android.support.v17.leanback.widget.ScaleFrameLayout>

【讨论】:

    【解决方案2】:

    是的,您可以更改卡片的缩放系数:

    一种方法是上面提到的答案:使用缩放因子

     val listRowPresenter = ListRowPresenter(ZOOM_FACTOR_LARGE)
    

    第二种方法是从dimen.xml文件中更改ZOOM_FACTOR的分数值。

    这里是所有的默认分数值,您可以根据需要自定义

    <item name="lb_focus_zoom_factor_xsmall" type="fraction">106%</item>
    <item name="lb_focus_zoom_factor_small" type="fraction">110%</item>
    <item name="lb_focus_zoom_factor_medium" type="fraction">114%</item>
    <item name="lb_focus_zoom_factor_large" type="fraction">118%</item>
    

    【讨论】:

      猜你喜欢
      • 2016-04-26
      • 1970-01-01
      • 2016-01-15
      • 2017-03-09
      • 2017-03-09
      • 1970-01-01
      • 2018-02-27
      • 2017-01-23
      • 1970-01-01
      相关资源
      最近更新 更多