首页 > 解决方案 > 在反应原生android中隐藏和显示时,TouchableOpacity 在绝对视图中不起作用

问题描述

在我现在正在编码的应用程序中,我创建了一个按钮,当我单击显示视图时。在那个观点上,有一个段落,在那个“这里”链接到一个网页。单击该链接时,我需要打开一个网站。位置“相对”它正在工作,但“绝对”位置不是,请帮我解决这个问题。我尝试了很多答案,但对我的情况不起作用!

代码:

 <View style={iconStyle}>
      <Pressable
        style={styles.container}
        onPress={() => {
          setEnabled(!enabled);
        }}>
        <Icon />
      </Pressable>
      {enabled && (
        <View style={[styles.content, contentStyle]}>
          <Text style={styles.text}>
            {content}{' '}
            {link && linkText && (
              <TouchableOpacity onPress={() => console.log('clicked')}>
                <Text>here</Text>
              </TouchableOpacity>
            )}
          </Text>
        </View>
      )}
    </View>

风格

const styles = StyleSheet.create({
  container: {
    width: 25,
    height: 20,
  },
  content: {
    position: 'absolute',
    marginBottom: 30,
    top: 25,
    zIndex: 1000,
    borderRadius: 5,
    padding: 8,
    width: 200,
    left: 0,
    backgroundColor: colors.green,
  },

  text: {
    justifyContent: 'space-between',
    fontSize: 12,
    fontFamily: fonts.regular,
  },
  linkText: {
    color: colors.darkBlue,
    textDecorationLine: 'underline',
  },
});

显示时的截图

标签: androidreact-native

解决方案


推荐阅读