我想要一个标题,左边是标题,右边是标题。之间是不同长度的文本。现在我希望文本剪切,如果它太长了。
<View style={styles.header}>
<View style={styles.headline}>
<Text style={styles.headlineFluorine}>{"Fluorine "}</Text>
<Text style={styles.headlinePath}>{this.props.text}</Text>
</View>
<View ref="navi" style={styles.nav}>
<NavButton onPress={() => { this.props.navigator.push({id: 'drawings',}); }} text={textMyDrawings} />
<NavButton onPress={() => { this.props.navigator.push({id: 'users',}); }} text={textUsers} />
<NavButton onPress={() => { this.props.navigator.push({id: 'templates',}); }} text={textTemplates} />
<NavButton onPress={() => { this.props.navigator.push({id: 'logout',}); }} text={textLogout} />
</View>
</View>
header: {
flexDirection: 'row',
//justifyContent: 'space-around',
backgroundColor: '#DDDDDD',
},
headline: {
flexDirection: 'row',
overflow: 'hidden',
},
headlineFluorine: {
textAlign: 'left',
color: '#666666',
fontSize: 24,
margin: 10,
},
headlinePath: {
fontSize: 18,
textAlign: 'left',
margin: 13,
overflow: 'hidden',
},
nav: {
flexDirection: 'row',
},
答案 0 :(得分:0)
添加numberOfLines属性
<Text style={styles.headlinePath} numberOfLines='1'>{this.props.text}</Text>
...并将宽度设置为固定限制。
答案 1 :(得分:0)
在返回之前尝试子串?
var txtlimit = 25;
var myheadertext = (this.props.text).length>txtlimit ? (this.props.text).substring(0,txtlimit) : this.props.text;
然后
<Text style={styles.headlinePath}>{myheadertext}</Text>