微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

React Native Flex 样式问题

如何解决React Native Flex 样式问题

在此设置中无法将文本和图像并排排列: https://snack.expo.io/XZef1XEje

width 添加topHomeTextContainer 是否真的有助于排列元素?我尝试添加一个额外的 <View />,但没有任何作用。

如果链接失效:

import React,{ useState } from "react"
import { StyleSheet,Image,Text,TouchableOpacity,View } from "react-native"

const App = () => {
    return (
        <View stye={styles.topHomeContainer}>
            <View style={styles.topHomeTextContainer}>
                <Text style={styles.topHomeText}>Find Things</Text>
            </View>
            {/* <View style={styles.topHomeImageContainer}> */}
            <TouchableOpacity
                style={styles.topHomeImage}
            >
                <Image
                    style={styles.arrowIcon}
                    source={{uri:"https://i.pinimg.com/originals/4d/4d/b9/4d4db9216358ec06d74d20507ed75c49.png"}}
                />
            </TouchableOpacity>
            {/* </View> */}
        </View>
    )
}

const styles = StyleSheet.create({
    topHomeContainer: {
        flex: 1,flexDirection: `row`,alignItems: `stretch`,justifyContent: `center`,height: 100,marginBottom: 15,},topHomeTextContainer: {
        //width: `65%`,topHomeText: {
        color: `rgb(0,0)`,fontFamily: "GothamMedium",fontSize: 20,fontWeight: `500`,letterSpacing: 0,// topHomeImageContainer: {
    //     width: scaleHelper.w(32),// },//topHomeImage: { width: 32 },arrowIcon: {
        width: 32,height: 32
    },})

export default App

更新 1:为图像添加宽度和高度。

解决方法

您应该将 widthheight 样式赋予 Image 样式 - arrowIcon。也无需将 width 赋予 topHomeImage 样式。

// topHomeImage: {
//     width: 32 
// },arrowIcon: {
    width: 32,height: 32
},

更新

另外,我在您的代码中发现了一个错字 stye

改变

<View stye={styles.topHomeContainer}>

<View style={styles.topHomeContainer}>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。