Android TV:VerticalGridFragment 阴影尺寸和颜色 [英] Android TV: VerticalGridFragment shadow dimension and color

查看:26
本文介绍了Android TV:VerticalGridFragment 阴影尺寸和颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Android TV 应用程序,但我对 VerticalGridFragment 渲染的标准阴影不太满意,我希望它更小,更暗一点.

I'm working on an Android TV application but I'm not quite happy with the standard shadow rendered by the VerticalGridFragment, I'd like to have it smaller and a bit less darker.

我已经搜索了代码,但没有找到任何完整的工作解决方案.在我的 VerticalGridPresenter 子类中,我可以覆盖的唯一方法是 createShadowOverlayOptions 但我无法得到我想要的结果.

I've searched through the code but I didn't find any full working solution. In my VerticalGridPresenter subclass, the only method I can override is createShadowOverlayOptions but I can't get the result I want.

我想出的唯一解决方法是定义以下维度,以便覆盖支持库中声明的维度:

The only workaround I came up with is to define the following dimensions, so that the ones declared in the Support Library are overridden:

<dimen name="lb_material_shadow_details_z">3dp</dimen>
<dimen name="lb_material_shadow_focused_z">4dp</dimen>
<dimen name="lb_material_shadow_normal_z">3dp</dimen>

但这更像是一种黑客行为,而不是正确的解决方案.

But it's more an hack rather than a proper solution.

这是标准的阴影:

这是我使用当前 hack 得到的结果:

This is the result I get with my current hack:

正如你所见,它变小了,但我不能改变颜色.

As you can I see, it's smaller but I cannot change the color.

VerticalGridFragmentRowsFragment 类是否有设置阴影颜色和尺寸的正确方法?

Is there a proper way to set shadow color and dimension for VerticalGridFragment and RowsFragment classes?

我使用的是最新的 Leanback 版本:

I'm using latest Leanback version:

compile 'com.android.support:leanback-v17:25.2.0'

我的 minSdkVersion 是 17,因为有一个自定义的 Android TV 播放器,但它可以从 21 开始工作.

My minSdkVersion is 17 because of a custom Android TV player, but it's fine to have it working starting from 21.

推荐答案

实际上我之前曾向 Leanback 团队询问过这个问题,他们说自定义组件的推荐方法是通过覆盖样式和尺寸.所以这可能有助于缓解您的一些担忧.

I've actually asked the Leanback team about this before and they said the recommended way of customizing their components is through overriding the styles and dimens. So that might help assuage some of your worry.

但是,我们还必须自定义视图上的阴影.我们通过创建我们自己的视图和我们自己的视图展示器(而不是使用他们的 ImageCardView)来做到这一点.有了它,我们就可以在演示级别设置自己的阴影.

However, we also had to customize the shadows on our views. We did this by creating our own views and our own view presenters (instead of using their ImageCardView). With that we were able to set our own shadows at the presentation level.

如果您查看 ListRowPresenter 文档说:

If you look at the documentation for ListRowPresenter the docs say:

ListRowPresenter 将默认阴影应用于每个子视图.调用 setShadowEnabled(boolean) 禁用阴影.子类可以在 isUsingDefaultShadow() 中覆盖并返回 false 并替换为它自己的影子实现.

ListRowPresenter applies a default shadow to each child view. Call setShadowEnabled(boolean) to disable shadows. A subclass may override and return false in isUsingDefaultShadow() and replace with its own shadow implementation.

要了解更多它们如何处理阴影,请查看 ListRowPresenter 的源代码,并查看 ShadowHelperShadowHelperApi21 类看看他们是如何实现向列表项添加阴影的.我们实际上只是复制了这两个类,因为它们是包本地的.

To see more of how they handle shadows, please look into the source code of ListRowPresenter and also check out the ShadowHelper and ShadowHelperApi21 classes to see how they've implemented adding shadows to their list items. We actually just copied over those two classes since they are package-local.

您还可以覆盖 ListRowPresenter 中的 ShadowOverlayHelper.Options createShadowOverlayOptions(),这使您可以更改角半径以及聚焦和未聚焦 z.

You can also override ShadowOverlayHelper.Options createShadowOverlayOptions() in ListRowPresenter which gives you some ability to change corner radius and focused and unfocused z.

这篇关于Android TV:VerticalGridFragment 阴影尺寸和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆