[英]React-native text layout
我有以下 react-native 组件:
const TaskItem = () => {
return (
<>
<View
style={{
marginTop: 32,
marginHorizontal: 8,
display: 'flex',
flexDirection: 'row',
backgroundColor: 'red',
}}
>
<Text style={{ marginRight: 8 }}>
<Text style={{ backgroundColor: 'green' }}>Title:</Text>
</Text>
<Text>
<Text
style={{
fontWeight: 'bold',
color: '#000000',
backgroundColor: 'blue',
}}
numberOfLines={2}
>
Very long text Very long text Very long text Very long text Very long text
</Text>
</Text>
</View>
</>
);
};
它产生以下屏幕(用于调试的背景颜色):
我想要的是:
marginHorizontal: 8
)这就是解决方案。 从实施中检查这一点
你的TaskItem
应该是这样的
const TaskItem = () => {
return (
<View
style={{
marginTop: 32,
marginHorizontal: 8,
flexDirection: 'row',
borderColor: 'black',
borderWidth: 1,
}}>
<Text style={{ marginRight: 8 }}>Title:</Text>
<View style={{ flex: 1, flexDirection: 'row' }}>
<Text
style={{
fontWeight: 'bold',
color: '#000000',
}}
numberOfLines={2}>
Very long text Very long text VeVery long text Very long text Very
long text Very long text VeryVery long text Very long text Very long
text Very long text VeryVery long text Very long text Very long text
Very long text VeryVery long text Very long text Very long text Very
long text Veryry long text Very long text Very long text
</Text>
</View>
</View>
);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.