反应本性:滚动浏览的透明视图
我有问题设置透明度,以供滚动浏览以外的视图。我正在使用博览会。这个想法是,当您滚动长期滚动浏览内容时,您应该在底部视图后面看到它。我已经尝试了obacity
属性,并使用rgba(x,x,x,x,0.5)
设置背景颜色,没有运气。相对于其背后的滚动浏览内容,Scrollview之外的任何东西看起来完全不透明。
基本代码(零食的链接在下面):
export default function App() {
return (
<View style={styles.container}>
<ScrollView>
<View style={styles.transparentWrapper}>
<Text style={styles.textElement}>This is some text wrapped in a transparent View</Text>
</View>
<Text style={styles.paragraph}>
Lorem....
</Text>
<Text style={styles.paragraph}>
Lorem ...
</Text>
</ScrollView>
<View style={styles.bottomPart}>
<Text style={styles.textElement}>This is some text. Its wrapping view is transparent but I cannot see the lorem text underneath it.</Text>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
},
paragraph: {
fontSize: 30,
marginBottom: 15,
},
textElement: {
color: 'blue',
},
transparentWrapper: {
position: 'absolute',
height: 100,
justifyContent: 'center',
top: 450,
left: 50,
backgroundColor: 'transparent',
zIndex: 999,
},
bottomPart: {
height: 50,
backgroundColor: 'transparent',
}
});
完整的小吃在这里: https://snack.expo.expo.dev/@wastelandtime/scrollview-scrollview-time/scrollview-transparansparency
I'm having problems setting transparency for a View that is outside of the ScrollView. I'm using Expo. The idea is that when you scroll the long scrollview content, you should just about to see it behind the bottom view. I've tried the opacity
property as well as setting the background color using rgba(x,x,x, 0.5)
with no luck. It looks like anything outside the Scrollview is totally opaque in relation to the scrollview content behind it.
Basic Code (the link to the snack is below):
export default function App() {
return (
<View style={styles.container}>
<ScrollView>
<View style={styles.transparentWrapper}>
<Text style={styles.textElement}>This is some text wrapped in a transparent View</Text>
</View>
<Text style={styles.paragraph}>
Lorem....
</Text>
<Text style={styles.paragraph}>
Lorem ...
</Text>
</ScrollView>
<View style={styles.bottomPart}>
<Text style={styles.textElement}>This is some text. Its wrapping view is transparent but I cannot see the lorem text underneath it.</Text>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
},
paragraph: {
fontSize: 30,
marginBottom: 15,
},
textElement: {
color: 'blue',
},
transparentWrapper: {
position: 'absolute',
height: 100,
justifyContent: 'center',
top: 450,
left: 50,
backgroundColor: 'transparent',
zIndex: 999,
},
bottomPart: {
height: 50,
backgroundColor: 'transparent',
}
});
Full snack is here:
https://snack.expo.dev/@wastelandtime/scrollview-transparency
Here's an expected outcome. The top blue text is wrapped in a transparent view (and this is what it's supposed to look like) it's not a problem as it's within the ScrollView.
The bottom blue text does not seem to honour any transparency in terms of the scroll content behind it (I'd like just to see the blue text with complete transparency on the wrapping View.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以在没有
位置的情况下实现它:'Absolute'
,并以这种方式使用负边距,使用负面边距可以将文本推到上方的
零食链接 https://snack.expo.dev/cjbbhsczg
it can be achieved without
position: 'absolute'
, with negative margin in this way,using negative top margin the text can be pushed upwards
snack link here https://snack.expo.dev/CJBbhSCzg
将Bottompart位置设置为绝对和底部:0
您应该得到 this 。
您可能还需要将
marginbottom:50,
添加到卷轴内部的最后一个元素,如果您在底部的底部中放置一个实体元素。Setting bottomPart position to absolute and bottom: 0
You should get something like this.
You may also want to add
marginBottom: 50,
to the last element inside the ScrollView if you'll put a solid element inside the bottom part.