谁能帮帮我? 我正在为其使用 React Native Expo SDK 42,它仅在 Android 上显示此错误。 我的 iOS 设备上没有错误。我尝试了所有方法,例如添加 Overflow: "hidden"但仍然没有用。
不知道这个错误发生在哪里。我认为它在投资组合部分,但我认为那里没有问题。
import { ScrollView, StyleSheet, Text, View } from "react-native";
import { StatusBar } from "expo-status-bar";
import { SafeAreaView } from "react-native-safe-area-context";
import StockListItem from "../components/StockListItem";
import { useBottomTabBarHeight } from "@react-navigation/bottom-tabs";
const Home = () => {
const tabBarHeight = useBottomTabBarHeight();
return (
<SafeAreaView style={[styles.container, { paddingBottom: -tabBarHeight }]}>
<ScrollView
showsVerticalScrollIndicator={false}
contentContainerStyle={styles.contentContainer}
style={styles.scollContainer}
>
<View style={styles.portfolio}>
{/* Money */}
<View style={styles.moneyContainer}>
<View style={styles.invested}>
<Text style={styles.moneyText}>Invested</Text>
<Text style={styles.moneyNumber}>10,000</Text>
</View>
<View style={styles.current}>
<Text style={styles.moneyText}>Current</Text>
<Text style={styles.moneyNumber}>10,000</Text>
</View>
</View>
{/* Underline */}
<View
style={{
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
width: "90%",
}}
>
<View
style={{
flex: 1,
height: 2,
borderRadius: "50%",
backgroundColor: "#808080",
}}
/>
</View>
{/* Profit */}
<View style={styles.profitContainer}>
<View style={styles.profit}>
<Text style={styles.profitText}>P&L</Text>
</View>
<View style={styles.profitValue}>
<Text style={styles.profitNumber}>+10,000</Text>
</View>
</View>
</View>
<StockListItem />
</ScrollView>
<StatusBar style="light" />
</SafeAreaView>
);
};
export default Home;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#161616",
alignItems: "center",
justifyContent: "center",
},
scollContainer: {
width: "100%",
},
contentContainer: {
alignItems: "center",
justifyContent: "center",
},
portfolio: {
marginTop: 10,
height: 150,
width: "90%",
backgroundColor: "#242424",
borderRadius: 10,
overflow: "hidden",
alignItems: "center",
justifyContent: "center",
},
moneyContainer: {
flex: 2,
width: "90%",
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
},
invested: {
width: "50%",
},
current: {
width: "50%",
},
moneyText: {
color: "#808080",
fontSize: 18,
fontWeight: "500",
},
moneyNumber: {
color: "#ffffff",
fontSize: 24,
fontWeight: "500",
},
profitContainer: {
flex: 2,
width: "90%",
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
},
profit: {
width: "50%",
},
profitValue: {
width: "50%",
},
profitText: {
color: "#808080",
fontSize: 18,
fontWeight: "500",
},
profitNumber: {
color: "green",
fontSize: 24,
fontWeight: "500",
},
});```
最佳答案
尝试使用不带引号的 50 :
<View
style={{
flex: 1,
height: 2,
borderRadius: "50%", => borderRadius:50,
backgroundColor: "#808080",
}}
/>
另请注意错误,“java.lang.string cannot be cast to java.lang.Double”表示您将字符串 ("50%") 转换为 double(带点的数字,例如 1.0 )
边框半径应为数字 - https://reactnative.dev/docs/view-style-props#borderradius
关于reactjs - 更新由 : RCTView java. lang.String 管理的 View 的属性 'borderStyle' 时出错,无法转换为 java.lang.Double,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69517968/