Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使加载器在视图上居中_Javascript_Jquery_Reactjs_React Native - Fatal编程技术网

Javascript 如何使加载器在视图上居中

Javascript 如何使加载器在视图上居中,javascript,jquery,reactjs,react-native,Javascript,Jquery,Reactjs,React Native,在一个显示页面的视图中,我需要显示加载器,但加载器需要在中间显示 var LoaderPositionCenter = React.createClass({ render:function(){ return(<View style= {{backgroundColor:'blue',flex:1,justifyContent:'center',alignItems:'center'}> <View>

在一个显示页面的视图中,我需要显示加载器,但加载器需要在中间显示

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>)
    }
})
var LoaderPositionCenter=React.createClass({
render:function(){
返回(
一
一
一
一
一
一
一
一
textsds DSD
)
}
})
在第一次查看内容时,我需要将加载程序显示为中心,如何使用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>
        );
      }
    });
var-Example=React.createClass({
getInitialState:函数(){
返回{状态:“按钮”}
},
单击:函数(){
这个.setState({status:“buttonText”});
},
render(){
返回(
{
{this.state.status}
}
一
一
一
一
一
一
一
一
一
一
一
一
一
一
一
一
一
一
一
一
一
一
一
一
一
一
);
}
});

如何禁用表示位置的内容视图:使用flexbox或其他“绝对”视图您可以将外部容器设置为具有以下样式属性:

flex: 1,
alignItems: 'center', 
justifyContent: 'center'
我已经设置了一个完整的项目,并将整个代码粘贴到下面:

“严格使用”;
var React=require('React-native');
变量{
评估学,
样式表,
文本,
看法
活动指示器
}=反应;
var SampleApp=React.createClass({
getInitialState:函数(){
返回{
动画:正确
}
},
render:function(){
返回(
);
}
});
var styles=StyleSheet.create({
容器:{
弹性:1,
对齐项目:“居中”,
为内容辩护:“中心”,
背景颜色:“#ddd”
},
});
AppRegistry.registerComponent('SampleApp',()=>SampleApp);

我想我会尽力帮你解决这个问题,但时间不早了,我累了。然而,如果你深入研究,我认为答案可以在这里找到。有一个组件也可能非常有用。祝你好运我也看到了。。。谢谢Chris Geirman。实际上我想为android和ios使用这个加载程序make center,但react native Model仅适用于ios。明白,我不是建议你多使用它们,而是建议你了解它们的工作原理,因为你正在尝试解决类似的问题是的,我理解克里斯·盖曼。谢谢你,纳德·达比特。它在IOS上运行,但我如何才能在android上实现同样的效果呢?因为在我的项目中,我对android和IOS都使用了相同的代码。我想我不明白你想要实现什么。我以为你想在内容顶部创建一个以微调器为中心的覆盖。很高兴纳德支持我们:)。ActivityIndicatorIOS只针对iOS,但这里有一个()声称是跨平台的。还有很多其他的,我想在内容的顶部创建一个以微调器为中心的覆盖。现在我用flexbox实现了这一点,但我有一个问题,当微调器加载时,覆盖内容应该被禁用。我用working One更新了上面的代码我用react native gifted spinner工作,但在添加内容时加载程序会下降,但在我的场景中,加载程序始终应居中,并且在加载程序运行时,用户无法对内容执行操作
'use strict';

var React = require('react-native');
var {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  ActivityIndicatorIOS
} = React;

var SampleApp = React.createClass({

  getInitialState: function(){
    return {
        animating: true
    }
  },

  render: function() {
    return (
      <View style={styles.container}>
       <ActivityIndicatorIOS animating={this.state.animating} style={[{height: 80}]} size="large" />
      </View>
    );
  }

});

var styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center', 
    justifyContent: 'center',
    backgroundColor: '#ddd'
  },
});

AppRegistry.registerComponent('SampleApp', () => SampleApp);