【发布时间】:2016-11-19 11:39:40
【问题描述】:
我希望视图占屏幕的三分之一(水平),因此我创建了 3 个视图,并在每个视图上设置了 flex: 1。
现在如果我在里面放一个<Text>,它会比另外两个稍大。
如何保持它占屏幕的三分之一?
这里有一些代码:
import React, { Component } from 'react';
import { AppRegistry, Text, View } from 'react-native';
class FlexDirectionBasics extends Component {
render() {
return (
<View style={{flex: 1, flexDirection: 'row'}}>
<View style={{flex: 1, backgroundColor: 'powderblue'}}>
<Text style={{backgroundColor: 'red'}}>text</Text>
</View>
<View style={{flex: 1, backgroundColor: 'skyblue'}} />
<View style={{flex: 1, backgroundColor: 'steelblue'}} />
</View>
);
}
};
AppRegistry.registerComponent('AwesomeProject', () => FlexDirectionBasics);
【问题讨论】:
标签: react-native flexbox