react-native app 屏幕适配方案(按照设计稿像素大小写就行)
import React, { Component,PropTypes } from 'react';
import { Dimensions,PixelRatio,Platform,StatusBar,View } from 'react-native';
let props = {};
export default class Resolution {
static get(useFixWidth = true) {
return useFixWidth ? {
...props.fw
} : {
...props.fh
}
}
static setDesignSize(dwidth = 750, dheight = 1336, dim = "window") {
let designSize = {
width: dwidth,
height: dheight
};
let navHeight = Platform.OS === 'android' ? StatusBar.currentHeight : 0;
let pxRatio = PixelRatio.get(dim);
let {
width,
height
} = Dimensions.get(dim);
if (dim != "screen") height -= navHeight;
let w = PixelRatio.getPixelSizeForLayoutSize(width);
let h = PixelRatio.getPixelSizeForLayoutSize(height);
let fw_design_scale = designSize.width / w;
fw_width = designSize.width;
fw_height = h * fw_design_scale;
fw_scale = 1 / pxRatio / fw_design_scale;
let fh_design_scale = designSize.height / h;
fh_width = w * fh_design_scale;
fh_height = designSize.height;
fh_scale = 1 / pxRatio / fh_design_scale;
props.fw = {
width: fw_width,
height: fw_height,
scale: fw_scale,
navHeight
};
props.fh = {
width: fh_width,
height: fh_height,
scale: fh_scale,
navHeight
};
console.log("winSize", JSON.stringify({
width,
height
}))
console.log("winPixelSize", JSON.stringify({
width: w,
height: h
}))
console.log("pxRatio", pxRatio)
console.log("fixWidth", JSON.stringify(props.fw))
console.log("fixHeight", JSON.stringify(props.fh))
}
static FixWidthView = (p) => {
let {
width,
height,
scale,
navHeight
} = props.fw;
return ( <
View {
...p
}
style = {
[p.style, {
marginTop: navHeight,
width: width,
height: height,
transform: [{
translateX: -width * .5
},
{
translateY: -height * .5
},
{
scale: scale
},
{
translateX: width * .5
},
{
translateY: height * .5
}
]
}]
}
/>
);
};
static FixHeightView = (p) => {
let {
width,
height,
scale,
navHeight
} = props.fh;
return ( <
View {
...p
}
style = {
[p.style, {
marginTop: navHeight,
width: width,
height: height,
transform: [{
translateX: -width * .5
},
{
translateY: -height * .5
},
{
scale: scale
},
{
translateX: width * .5
},
{
translateY: height * .5
}
]
}]
}
/>
);
};
};
//init
Resolution.setDesignSize();
react-native app 屏幕适配方案(按照设计稿像素大小写就行)的更多相关文章
- Flutter 移动端屏幕适配方案和制作
flutter_screenutil插件 flutter 屏幕适配方案,让你的UI在不同尺寸的屏幕上都能显示合理的布局! 注意:此插件仍处于开发阶段,某些API可能尚未推出. 安装依赖: 安装之前请查 ...
- JavaScript强化教程 —— Cocos2d-JS的屏幕适配方案
1. 设置屏幕适配策略(Resolution Policy) 如果你还没有用过Resolution Policy,只需要在游戏载入过程完成之后(cc.game.onStart函数回调中),调用下面的代 ...
- Unity2D多分辨率屏幕适配方案(转载)
一下内容转自:http://imgtec.eetrend.com/forum/3992 此文将阐述一种简单有效的Unity2D多分辨率屏幕适配方案,该方案适用于基于原生开发的Unity2D游戏,即没有 ...
- Cocos2d-JS的屏幕适配方案
Cocos2d引擎为游戏开发者提供了屏幕适配策略(Resolution Policy)解决方案. 使用方式 1. 设置屏幕适配策略(Resolution Policy) 如果你还没有用过Resolut ...
- cocos2dx屏幕适配方案
我们在利用cocos2dx来开发游戏时,在开始时就不可避免的会遇到屏幕适配问题,来使我们的游戏适应移动终端的各种分辨率大小.目前,大家采用的屏幕适配方案不一,网上的资料也比较丰富,下面我也将自己使用的 ...
- [原创]一种Unity2D多分辨率屏幕适配方案
此文将阐述一种简单有效的Unity2D多分辨率屏幕适配方案,该方案适用于基于原生开发的Unity2D游戏,即没有使用第三方2D插件,如Uni2D,2D toolkit等开发的游戏,NGUI插件不受这个 ...
- Android 屏幕适配方案
转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/45460089: 本文出自:[张鸿洋的博客] 1.概述 大家在Android开发 ...
- 实用Android 屏幕适配方案分享
转载地址:http://blog.csdn.net/gao_chun/article/details/45645051 真正可用,并且简单易行,可以在多个屏幕大小和屏幕密度上有良好表现的Android ...
- 给你一个全自动的屏幕适配方案(基于SW方案)!—— 解放你和UI的双手
Calces系列相关文章:Calces自动实现Android组件化模块构建 前言 屏幕适配一直是移动端开发热议的问题,但是适配方案往往在实际开发的时候会和UI提供的设计稿冲突.本文主要是基于官方推荐的 ...
随机推荐
- kaggle下载不了比赛数据?
先看这个 kaggle数据集下载 -------------------------------- 有时发现下载不了kaggle数据 关于kaggle没有办法下载数据集dataset问题 安装kagg ...
- 学习python-20191217(1)-Python Flask高级编程开发鱼书_第04章_应用、蓝图与视图函数
视频01: flask框架:最上层是app,它就像一个插线板一样,比如可以插入蓝图,还可以插入其他各种flask插件. 每个蓝图又可以插入很多视图函数,并可指定静态文件夹和模板文件夹. 好的代码结构, ...
- deeplearning.ai 卷积神经网络 Week 1 卷积神经网络
1. 传统的边缘检测(比如Sobel)手工设计了3*3的filter(或者叫kernel)的9个权重,在深度学习中,这9个权重都是学习出来的参数,会比手工设计的filter更好,不但可以提取90度.0 ...
- [LC] 152. Maximum Product Subarray
Given an integer array nums, find the contiguous subarray within an array (containing at least one n ...
- MOOC(1)-使用pycharm新建Django项目、开发post接口
https://www.cnblogs.com/liqu/p/9308966.html 1.安装Django的两种方式: > 1) pip install django 2)下载离线安装包,进入 ...
- shortcuts 快捷键
Home » Linux » shortcuts 快捷键 Page Updated 2018-12-12 19:23 shortcuts 快捷键 移动光标 Ctrl – a :移到行首 Ctrl – ...
- configure: error: C compiler cannot create executables报错处理
在测试环境安装php的imagick扩展在执行./configure生成编译文件时出现报错如下: 通过查看config.log发现有报错,在网上经验教程里发现前面的报错不管,直奔最后的报错即可,发现是 ...
- android 中webview的屏幕适配问题
两行代码解决WebView的屏幕适配问题 一个简单的方法,让网页快速适应手机屏幕,代码如下 1 2 WebSettings webSettings= webView.getSettings(); we ...
- 快速入门和查询Python
评分: 4.5 作者: Ryan Lu 类别:Python 时间: 1. 注释 三种方式: 单行注释以 # 开头 多行注释用三个单引号 ''' 将注释括起来 多行注释用三个双引号 "&quo ...
- HTML笔记02
网页中的颜色有三种表示方法 颜色单词:blue.green.red.yellow 10进制表示:rgb(255,0,0).rgb(0,255,0).rgb(0,0,255) 16进制表示:#ff000 ...