我有一个组件,我想要在 React Native 中从右下到左上的线性渐变,我尝试使用“react-native-线性渐变”,但它不起作用。
成分 :
//渲染返回
return(
<LinearGradient colors={['#4c669f', '#3b5998', '#192f6a']} >
<View style={styles.container}>
<View style={styles.topPart}>
<Header ></Header>
<Content ></Content>
</View>
<Footer style={styles.footer}></Footer>
</View>
</LinearGradient>
);
请指导如何实现这一目标。
安装后react-native-linear-gradient
图书馆:
npm install --save react-native-linear-gradient
尝试将项目的所有依赖项链接为,
react-native link
并确保您正在导入LinearGradient
as,
import LinearGradient from 'react-native-linear-gradient';
最后但也是最重要的事情设定了一些flex
对您的价值LinearGradient
,
<LinearGradient
colors={['#6e45e2', '#88d3ce']}
style = { styles.container }>
<View>
//your elements here
</View>
</LinearGradient>
你的线性渐变style
as,
const styles = StyleSheet.create({
container: {
flex: 1,
}
});
Note我确信你的渐变不可见,因为flex
值,只需添加即可。它肯定会起作用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)