Align two children differently in react native

Deadly 提交于 2020-01-17 04:34:06

问题


I'd like to have a header with a back button to the left and a text/title in the center of the header.

Like this:

<View style={styles.topbar}>
    <TouchableOpacity>
        <Text style={styles.topbarButton}>{" <"}</Text>
    </TouchableOpacity>
    <View>
        <Text style={styles.topbarText}>Title</Text>
    </View>
</View>

I'm trying to use flex in styles.topbar but nothing of what I tried seems to work.

I am pretty new to flex and React Native so some help with the styles would be great.

Thanks all.


回答1:


Here we go:

<View style={{width:devicewidth,flexDirection:'row',height:40,top:0,position:'absolute'}}>
   <TouchableOpacity style={{left:0,position:'absolute',alignItems:'flex-    start'}}>
      <Text style={styles.topbarButton}>{" <"}</Text>
   </TouchableOpacity>
     <View style={{justifyContent:'center'}}>
      <Text style={styles.topbarText}>Title</Text>
     </View>
</View>

The above code will print back button at the top left and text at the center. Flex direction is used to indicate view to print in a row direction.



来源:https://stackoverflow.com/questions/41212593/align-two-children-differently-in-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!