【发布时间】:2018-08-30 03:31:29
【问题描述】:
我一直在尝试开发下面提到的屏幕:
为此,我创建了以下组件:
import React, {Component} from 'react';
import {View, Text, StyleSheet, ImageBackground, Image} from 'react-native';
import Balance from './Balance.js'
class AccountHeader extends React.Component{
render(){
return(
<ImageBackground
source={require('../images/lawrance.jpg')}
style={styles.container}>
<View style={styles.overlay}></View>
<Text style = {[styles.textStyle, {paddingTop: 10}]} >My Account</Text>
<Image source= {require('../images/lawrance.jpg')}
style={styles.avatarStyle}/>
<Text style = {styles.textStyle} > Jenifer Lawrance</Text>
<Text style = {styles.textStyle} > +14155552671</Text>
<Balance style= {styles.balanceContainer}/>
</ImageBackground>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor:'red',
opacity: 0.6
},
overlay: {
backgroundColor:'transparent',
opacity: 0.6
},
avatarStyle: {
width:100,
height: 100,
marginTop: 10,
borderRadius: 50,
alignSelf: 'center',
},
textStyle: {
marginTop: 10,
fontSize: 18,
color: "#FFFFFF",
fontWeight: 'bold',
alignSelf: 'center',
},
balanceContainer:{
padding:10,
}
});
export default AccountHeader;
现在有两个问题:
- 更改
ImageBackground的不透明度也会更改其子项的不透明度 - 无法更改不透明度的颜色
任何帮助表示赞赏!
设计画面:
开发屏幕
【问题讨论】:
-
您是否尝试删除容器的不透明度?根据给定的样式,容器还包含不透明度值,因此整个容器都会受到影响。
-
@rohan kangale:是的。但我想在背景图像上应用不透明度。
-
backgroundColor="rgba(32,36,100,0.6)" 像这样使用背景颜色
-
@Paras Watts:根本不工作!请注意它是“ImageBackground”而不是图像
-
尝试将图像移到 ImageBackground 之外(您还需要更改样式)。
标签: javascript css react-native imagebackground