Android TV: VerticalGridFragment shadow dimension and color

我与影子孤独终老i 提交于 2020-01-02 05:46:12

问题


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.

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 standard shadow:

This is the result I get with my current hack:

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

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

I'm using latest Leanback version:

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

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


回答1:


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.

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.

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

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.

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.

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



来源:https://stackoverflow.com/questions/42623677/android-tv-verticalgridfragment-shadow-dimension-and-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!