react-native - 反应原生样式组件
问题描述
我正在尝试设置组件的样式,但无法弄清楚如何做几件事。1) 我想为我的组件 100% 应用背景颜色
return (
<TouchableWithoutFeedback
style={styles.touchable}
onPress={() =>
this.props.navigation.navigate('Quotes', { name: this.props.name })}
>
<View style={styles.viewStyle}>
<Image
source={this.props.image}
key={this.props.image}
style={styles.imageStyle}
/>
<Text style={styles.textStyle}> {this.props.name} </Text>
</View>
</TouchableWithoutFeedback>
);
}
}
const styles = {
imageStyle: {
height: 100,
width: 100
},
touchable: {
width: '100%',
backgroundColor: 'black'
},
viewStyle: {
height:100,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
backgroundColor: 'black'
},
textStyle: {
marginLeft: 20,
width: 120,
fontWeight: 'bold',
fontSize: 15
}
}
我尝试将背景颜色应用于可触摸标签视图标签,但这些都不起作用。此外,我想使用 justifyContent: flex-start 将我的图像放置在组件的左上角。但是我在视图标签中的元素保持居中。
父组件是:
render() {
const {listStyle} = styles
return (
<ScrollView style={listStyle}>
{this.renderCharacters(this.props.matches)}
</ScrollView>
);
}
}
const styles = {
listStyle: {
width: '100%',
height: '100%'
}
}
解决方案
推荐阅读
- python - Python中没有monad?
- java - 无法从 Java 中的不同模块解析类(Intellij)
- json - Arduino 和 Xojo 的 json 问题
- python - 如何在python中将一个字符串分成10个字母?
- python - 当我使用 estiamtor.train() 从检查点重新开始训练时,它会继续使用最后一批数据进行训练吗?
- reactjs - 如何调用更新反应上下文状态/或从非反应类调用方法?
- mysql - 我无法使用 sequelize 连接到 mysql
- mysql - pip install mysqlclient 在 linux 主机上不起作用
- c++ - 模板特化示例
- python - 制作一个空矩阵