alignSelf Не вносит никаких изменений с макетом "React native" - PullRequest
0 голосов
/ 28 сентября 2018

JSX-выражение компонента, как указано ниже

<ImageBackground source={require('../images/background.jpg')} 
      style={styles.container}>        
        <View style={styles.container}>
            <View style={styles.viewStyleOne}>
                <Text style={styles.textStyle}> 1 </Text>
            </View>

            <View style={styles.viewStyleTwo}>
                <Text style={styles.textStyle}> 2 </Text>
            </View>

            <View style={styles.viewStyleThree}>
                <Text style={styles.textStyle}> 3 </Text>
            </View>
        </View>
</ImageBackground>

Стиль

const styles = StyleSheet.create({
container:{
    flex: 1,
    flexDirection:'row',
    alignItems:'center', 
    justifyContent: 'center'
},
viewStyleTwo : {
    width:100,
    height:40,
    justifyContent : 'center',
    alignItems:'center', 
    backgroundColor: '#4DF25F'
},
viewStyleOne :{
    width:40,
    height:40,
    justifyContent : 'center',
    alignItems:'center', 
    backgroundColor: '#B54BF1',
    alignSelf : 'flex-start'
},
viewStyleThree:{
    width:40,
    height:40,
    justifyContent : 'center',
    alignItems:'center', 
    backgroundColor: '#F3B54E'
},
textStyle:{
    textAlign:'center'
}});

enter image description here

viewStyleOne класс содержитсвойство alignSelf, но не вносило никаких изменений, оно должно быть вверху экрана

Ожидаемый результат должен быть таким, как показано на скриншоте

enter image description here

1 Ответ

0 голосов
/ 28 сентября 2018

Можете ли вы попробовать следующее,

const styles = StyleSheet.create({
    container:{
        flex: 1,
        top: 0, 
        // Option 01
        height: "100%", // Added
        // OR  // Option 02
        // bottom: 0,
        // left: 0,
        // right : 0,
        // position: 'absolute',
        flexDirection:'row',
        alignItems:'center', 
        justifyContent: 'center',
        backgroundColor: 'green'
    },
    viewStyleTwo : {
        width:40,
        height:40,
        justifyContent : 'center',
        alignItems:'center', 
        backgroundColor: '#4DF25F'
    },
    viewStyleOne :{
        width:40,
        height:40,
        justifyContent : 'center',
        alignItems:'center', 
        backgroundColor: '#B54BF1',
        alignSelf : 'flex-start'
    },
    viewStyleThree:{
        width:40,
        height:40,
        justifyContent : 'center',
        alignItems:'center', 
        backgroundColor: '#F3B54E'
    },
    textStyle:{
        textAlign:'center'
    }});

Дает этот пользовательский интерфейс

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...