反应本性:滚动浏览的透明视图

发布于 2025-02-04 20:29:10 字数 1821 浏览 5 评论 0原文

我有问题设置透明度,以供滚动浏览以外的视图。我正在使用博览会。这个想法是,当您滚动长期滚动浏览内容时,您应该在底部视图后面看到它。我已经尝试了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.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白鸥掠海 2025-02-11 20:29:10

可以在没有位置的情况下实现它:'Absolute',并以这种方式使用负边距,

  bottomPart: {
    height: 50,
    backgroundColor: 'transparent',
    marginTop: -50, // add this
  }

使用负面边距可以将文本推到上方的

零食链接 https://snack.expo.dev/cjbbhsczg

it can be achieved without position: 'absolute', with negative margin in this way,

  bottomPart: {
    height: 50,
    backgroundColor: 'transparent',
    marginTop: -50, // add this
  }

using negative top margin the text can be pushed upwards

snack link here https://snack.expo.dev/CJBbhSCzg

自由范儿 2025-02-11 20:29:10

将Bottompart位置设置为绝对和底部:0

bottomPart: {
    height: 50,
    backgroundColor: 'transparent',
    position: 'absolute',
    bottom: 0
  }

您应该得到 this

您可能还需要将marginbottom:50,添加到卷轴内部的最后一个元素,如果您在底部的底部中放置一个实体元素。

Setting bottomPart position to absolute and bottom: 0

bottomPart: {
    height: 50,
    backgroundColor: 'transparent',
    position: 'absolute',
    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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文