【发布时间】:2015-12-26 05:12:17
【问题描述】:
在显示该页面中的页面的一个视图上,我需要显示加载器,但加载器需要将其显示在中心。
var LoaderPositionCenter = React.createClass({
render:function(){
return(<View style= {{backgroundColor:'blue',flex:1,justifyContent:'center',alignItems:'center'}>
<View>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
</View>
<View style={{flex:1,justifyContent:'center',alignItems:'center',flexDirection:'row'}}>
<Text style={{textAlign:'center',color:'yellow'}}>
textsds dsdsdsd
</Text>
</View>
</View>)
}
})
在第一次查看内容时,我需要将加载器显示为中心,如何使用 flexbox 实现它
//新建一个
var Example = React.createClass({
getInitialState:function(){
return {status:"button"}
},
click:function(){
this.setState({status:"buttonText"});
},
render() {
return (
<View style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
position:'relative',
}}>
<View style={{//content view
position:'absolute',
top:0,
left:0,
right:0,
bottom:0,
}}>
<ScrollView>
{
<TouchableHighlight
underlayColor="#ffa456"
onPress={this.click}
>
<Text>{this.state.status}</Text>
</TouchableHighlight>
}
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
<Text>one</Text>
</ScrollView>
</View>
<View style={{
flex:1,
alignItems:'center',
justifyContent:'center'
}}>
<Image source={{uri:icons.loader}}
style= {styles.loader}/>
</View>
</View>
);
}
});
如何使用 flexbox 或其他方式禁用表示 position:'absolute' 视图的内容视图
【问题讨论】:
-
我想我会试着为你解决这个问题,但已经晚了,我也累了。但是,如果您深入研究,我认为可以在这里找到答案github.com/brentvatne/react-native-modal。还有一个
组件也可能非常有用。祝你好运! -
谢谢 Chris Geirman 。实际上我想为 android 和 ios 使用这个加载器制作中心,但 react-native-modal 仅适用于 ios。
-
明白了,我并不是建议您使用它们,而是建议您了解它们的工作原理,因为您正在尝试解决类似的问题
-
是的,我理解 Chris Geirman。谢谢
标签: javascript jquery reactjs react-native