如何处理 tvOS 和 Android TV 之间的 React Native 应用程序中的缩放问题? [英] How do I handle scaling issues in a React Native app between tvOS and Android TV?

查看:88
本文介绍了如何处理 tvOS 和 Android TV 之间的 React Native 应用程序中的缩放问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple TV 的原始分辨率似乎是 1920x1080(如预期),但对于 Android TV/Fire TV,它似乎是 961.5022957581195x540.8450413639423(根据 Dimensions.get('window')).

Native resolution for Apple TV seems to be 1920x1080 (as expected) but for Android TV / Fire TV it seems to be 961.5022957581195x540.8450413639423 (according to Dimensions.get('window')).

所以,当我在 Apple TV 上运行我的应用程序时,一切看起来都很好.但是当我在 Android TV 上运行它时,屏幕上没有任何显示.

So, when I run my app on Apple TV everything looks fine. But when I run it on an Android TV nothing fits on the screen.

有没有办法强制 Android TV 缩小所有内容?还是我必须为不同的设备创建两个不同的样式表来更改所有组件的字体大小和尺寸?

Is there a way to force the Android TV to shrink everything? Or do I have to create two different style sheets for the different devices to change font sizes and dimensions of all my components?

推荐答案

我们使用不同的方法,在 tv 的基本 Application 类上添加这个

We use a different approach, on the base Application class for tv we add this

class TvApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        Configuration configuration = new Configuration(base.getResources().getConfiguration());
        configuration.densityDpi = configuration.densityDpi / 2;

        Context newContext = base.createConfigurationContext(configuration);

        super.attachBaseContext(newContext);
    }
}

有了这个,我们就有了一致的宽度&使用维度时高度,我们可以在所有平台上使用相同的样式值,而无需在 JS 端做任何操作.

with this, we have consistent width & height when using dimensions, and we can use the same styling values on all platforms without doing any manipulation on the JS side.

它并不完美,但在为多个平台构建时更方便

it's not perfect, but it's more convenient when building for multiple platforms

这篇关于如何处理 tvOS 和 Android TV 之间的 React Native 应用程序中的缩放问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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