gpt4 book ai didi

javascript - React Native 上的背景图片和 ScrollView

转载 作者:数据小太阳 更新时间:2023-10-29 05:09:47 24 4
gpt4 key购买 nike

我正在使用 React Native 构建一个应用程序,并希望获得一个背景图像和一个覆盖在背景图像之上的 ScrollView ,例如雅虎天气应用程序。

但我无法让它工作。

请帮忙。

最佳答案

要得到这个效果,你需要设置一个绝对定位的图片,然后在View上面放一个ScrollView:

'use strict';

var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
Dimensions,
ScrollView,
Image
} = React;

let width = Dimensions.get('window').width

var SampleApp = React.createClass({

render: function() {
return (
<View style={{ flex:1, backgroundColor: 'transparent' }}>
<View>
<Image style={{ height: width, width: width, position: 'absolute', top:0, left:0 }} source={{ uri: 'http://i01.i.aliimg.com/wsphoto/v0/32297951629_5/5pcs-lot-The-Hollowan-Star-Nicolas-Cage-Stylish-Square-Pillowcase-Cushion-Pillow-Cover.jpg' }} />
</View>
<ScrollView style={{ flex:1 }}>
<View>
<Text>{ipsum}</Text>
</View>
</ScrollView>
</View>
);
}
});

var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 28,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
fontSize: 19,
marginBottom: 5,
},
});

AppRegistry.registerComponent('SampleApp', () => SampleApp);

let ipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

关于javascript - React Native 上的背景图片和 ScrollView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35013573/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com