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

查看:153
本文介绍了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.

这是标准阴影:

这是我当前被黑客入侵的结果:

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'

由于自定义Android TV播放器,我的minSdkVersion为17,但最好从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将默认阴影应用于每个子视图.调用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天全站免登陆