关于react-native的适配与布局方式
来源:互联网 发布:铁塔基础设计软件 编辑:程序博客网 时间:2024/06/06 09:22
个人比较倾向于利用屏幕宽度和高度以及relative相对距离来布局。
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */import React, {Component} from 'react';import { AppRegistry, StyleSheet, Text, View} from 'react-native';export default class Demo extends Component { render() { return ( <View style={styles.container}> <View style={styles.navigationBar}> </View> {/*距离顶部40px,一个宽600px,高200px居中的View*/} <View style={[styles.sizeView,{position:'relative'}]}> </View> {/*距离左侧20px,距离顶部80px,宽度400px,高度60px*/} <View style={[styles.bottomLeftView,{position:'relative'}]}> </View> {/*距离bottomLeftView右侧40px,距离顶部sizeView200px,宽度40px,高度200px*/} <View style={[styles.bottomRightView,{position:'relative'}]}> </View> </View> ); }}let Dimensions = require('Dimensions');let {width,height} = Dimensions.get('window');let Platform = require('Platform');let StatusBar = require('StatusBar');{/*如果UI设计师的原型图是以6S为基准,6S的屏幕宽度为1334像素,那么算出缩放比例*/}let scale = width/1334;let navHeight = Platform.OS === 'ios' ? 128*scale : StatusBar.currentHeight + 40*scale;const styles = StyleSheet.create({ container: { backgroundColor: 'yellow', width: width, height: height, }, navigationBar: { backgroundColor: 'red', width:width, height:navHeight, }, sizeView: { backgroundColor: 'green', marginTop: 40*scale, left: (width - 600*scale)/2, width: 600*scale, height: 200*scale, }, bottomLeftView: { backgroundColor: 'blue', marginTop:80*scale, left: 20*scale, width: 400*scale, height: 60*scale, }, bottomRightView: { backgroundColor: 'black', left: 20*scale + 400*scale + 40*scale, marginTop:200*scale, width: 40*scale, height: 200*scale, }});AppRegistry.registerComponent('Demo', () => Demo);
效果如图:
相对距离根据需求可以换成屏幕宽高的百分比,这样就可以适配各种分辨率了。
阅读全文
0 0
- 关于react-native的适配与布局方式
- React Native布局方式学习
- 关于 React Native 与 WebView 的通信
- React Native 学习笔记七(关于布局的使用)
- react-native的flex布局
- flexbox----react native中的布局方式
- react与native异步交互的几种方式
- React Native布局常识与技巧 一
- 关于React-Native的生命周期
- React Native listview(学习) 和 Item 布局适配
- React Native 的布局(容器属性)
- React-Native中的flexbox布局的使用
- React native FlexBox布局的基本用法
- React native的flexbox布局(三)
- react-native 布局
- React-Native中的布局
- React Native Flex布局
- react-native布局
- Android Sensor HAL层分析
- FTPrep, 49 Anagram
- mysql开启允许远程连接
- 线程实现方法
- Java线程池原理及几种线程池类型介绍
- 关于react-native的适配与布局方式
- 【Leetcode】【python】Merge k Sorted Lists
- YP2.1 Bits and Data Types (双语)
- Android并发编程之全方位解析AsyncTask
- Android并发编程之如何使用ReentrantReadWriteLock替代synchronized来提高程序的效率
- hdu 1022 栈的应用
- hdu 1039
- 动物书:PHP经典实例(第三版)小错误
- hdu 1023