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提供的设计稿冲突.本文主要是基于官方推荐的 ...
随机推荐
- abstract class
在面向对象(OOP)语言中,一个类可以有一个或多个子类,而每个类都有至少一个公有方法作为外部代码访问的接口.而抽象方法就是为了方便继承而引入的,现在来看一下抽象类和抽象方法分别是如何定义以及他们的特点 ...
- volatile与Synchronized
摘自: https://blog.csdn.net/zxh476771756/article/details/78685581 一.JVM内存模型: JVM将内存组织为主内存和工作内存两个部分. 主内 ...
- IDEA 中tomcat上面有个x 而且找不到配置tomcat的选项
在使用idea时候,准备启动服务器,tomcat突然上面有个xx 解决方式 在 File-settings-plugins 搜索tomcat 如果插件后面有 就重新取消之后再勾选,然后点应用就可以解决 ...
- 自定义一个简单的SegmentedControl
先大概看下我们想实现简单的效果 源码 // // DSegmentedControl.swift // IOS学习之自定义UISegmentedControl // // Created by din ...
- 吴裕雄--天生自然 R语言开发学习:功效分析(续一)
#----------------------------------------# # R in Action (2nd ed): Chapter 10 # # Power analysis # # ...
- jsPDF
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- <SDOI2009>学校食堂
我. 调了快一天 因为一个位置错误的感叹号 :-) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 狗dp #include<cstdio> #include<cstr ...
- python IO多路复用版FTP
需求: 实现文件上传及下载功能 支持多连接并发传文件 使用select or selectors
- centos上安装python环境
1.安装python-pip 首先安装epel扩展源: yum -y install epel-release 更新完成之后,安装pip: yum -y install python- ...
- JavaScript学习之内存
初学JavaScript时,看红皮书了解了JS基本类型和引用类型在内存中的位置,结果看了简书里的一篇文章,发现对这块的了解还是有些缺陷. 基本类型 JavaScript中的基本类型有五种:Undefi ...