我一直在努力开发下面提到的屏幕:

为此,我创建了以下组件:

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;

现在有两个问题:

  1. 更改ImageBackground的不透明度也会更改其子对象的不透明度
  2. 无法更改不透明度的 colored颜色

感谢您的帮助!

Design screen:

enter image description here

Developed Screen

enter image description here

推荐答案

使用这个代码,它是有效的,我只是做了一个小改动

import React, {Component} from 'react';
    import {View, Text, StyleSheet, ImageBackground, Image,Dimensions} from 'react-native';

class AccountHeader extends React.Component{
    render(){
        return(
            <ImageBackground
                source={{uri:'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSoOVTmb0ILbDI6ggGhPKUkn3v4UKc2dNB-Kjng7aGM14UbvzKY'}}
                style={styles.container}>
                    <View style={styles.overlay}>
                    <Text style = {[styles.textStyle, {paddingTop: 10}]} >My Account</Text>
                    <Image source= {{uri:'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSoOVTmb0ILbDI6ggGhPKUkn3v4UKc2dNB-Kjng7aGM14UbvzKY'}}
                        style={styles.avatarStyle}/>
                    <Text style = {styles.textStyle} > Jenifer Lawrance</Text>
                    <Text style = {styles.textStyle} > +14155552671</Text>
                    </View>
            </ImageBackground>
        );
    }
}     

const styles = StyleSheet.create({
  container: {

},            
overlay: {
    backgroundColor:'rgba(255,0,0,0.5)',
},
    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;

React-native相关问答推荐

如何重复使用expo 音频对象S录音?

领带麦克风在Reaction-Native-Incall-Manager中不工作

单击时更改ToucheableOpacity colored颜色 不起作用

React-Native:请纠正我对状态如何工作的误解 - 动态文本输入

无法在 M1 zsh 上运行 adb segmentation fault adb

调用 ES6 方法时绑定上下文.如何从称为回调的方法中访问对象?

library not found for -lRCTGeolocation

使用 applicationIdSuffix 时 React Native 应用程序不会启动

在关闭 react-native 时更改 Switch 的 colored颜色

react-native Http 拦截器

带有 xcode 模拟器的 react-native 有非常慢的alert

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.

当数据为空时,React-Native FlatList 呈现零状态

在 React Native 中,如何使用浅渲染测试我的组件?

在 React Native 中使用小数

ReactNative TextInput 不可见 iOS

由于对 sourcetree 的 husky 预推送,Git 推送失败

为什么我收到警告:函数作为 React 子级无效?

React 在任何根目录中都找不到入口文件

React Native:无法解析模块 fs