react native獲取屏幕的寬高及分辨率

React Native 獲取屏幕的寬高及分辨率web

var Dimensions = require ('Dimensions') ;   //首先引入,而後使用便可
export default class Rule extends Component {
    constructor(props) {
        super(props);
        this.state = {
            
        };
    }
    render() {
		return (
			<View style={styles.container}>
                <View style={styles.title}>
                    <Text style={styles.titleText}>屏幕的寬是:{Dimensions.get('window').width}</Text>
                     <Text style={styles.titleText}>屏幕的高是:{Dimensions.get('window').height}</Text>
                      <Text style={styles.titleText}>屏幕的設備分辨率是:{Dimensions.get('window').scale}</Text>
                </View>
		);
    }
}
const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'white',
        justifyContent: 'flex-start',
        alignItems: 'flex-start',
    },
	divideLine: {
	    height:0.5,
	    width: Dimensions.get('window').width - 20,
	    borderWidth: 0.5,
	    borderColor: '#cccccc',
	    borderStyle: 'solid',
	},
	title: {
	    width: Dimensions.get('window').width,
	    marginLeft: 20,
	    marginTop: 10,
	    marginBottom: 5,
	},
	titleText: {
	    fontSize: 36 / 2,
	    color: '#999999',
	    fontFamily:'PingFangSC-Regular',
	}
});

本文同步分享在 博客「zoepriselife316」(CSDN)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。ide

相關文章
相關標籤/搜索