我是靠谱客的博主 坚强水杯,最近开发中收集的这篇文章主要介绍html转换react native,React Native获取组件的宽高以及React Native屏幕dp与px转换计算,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1、React Native获取组件的宽高

2、以及React Native屏幕dp与px转换计算;

import React, {Component} from 'react';

import {

Text,

View,

findNodeHandle,

UIManager,

TouchableOpacity,

Dimensions,

PixelRatio,

} from 'react-native';

const {width, height} = Dimensions.get('window');

const screenWidth = width;

const screenHeight = height;

const dpToPx = PixelRatio.get();

export default class App extends Component {

render() {

return (

onPress={() => {

const handle = findNodeHandle(this.refs.view);

UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {

console.log('相对父视图位置x:', x);

console.log('相对父视图位置y:', y);

console.log('组件宽度width:', width);

console.log('组件高度height:', height);

console.log('距离屏幕的绝对位置x:', pageX);

console.log('距离屏幕的绝对位置y:', pageY);

console.log('screenWidth: ', screenWidth);

console.log('screenHeight: ', screenHeight);

console.log('dpToPx: ', dpToPx);

console.log('dpToPx * screenWidth: ', dpToPx * screenWidth);

console.log('dpToPx * screenHeight: ', dpToPx * screenHeight);

});

}}>

ref='text'

style={{marginTop: 100, backgroundColor: 'cyan'}}

onPress={() => {

const handle = findNodeHandle(this.refs.text);

UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {

console.log('相对父视图位置x:', x);

console.log('相对父视图位置y:', y);

console.log('组件宽度width:', width);

console.log('组件高度height:', height);

console.log('距离屏幕的绝对位置x:', pageX);

console.log('距离屏幕的绝对位置y:', pageY);

});

}}

>点击获取这几个字的长度

);

}

}

最后

以上就是坚强水杯为你收集整理的html转换react native,React Native获取组件的宽高以及React Native屏幕dp与px转换计算的全部内容,希望文章能够帮你解决html转换react native,React Native获取组件的宽高以及React Native屏幕dp与px转换计算所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部