react-native - {Flex: 1} 不适用于相对定位
问题描述
我希望第二个View
相对位于第一个下方的 -50 处View
,但第二个View
不会完全延伸到底部。
import React from 'react';
import {View, Text} from 'react-native';
export const OverlayStorybook = () => {
return (
<View style={{flex: 1}}>
<View style={{height: 100, backgroundColor: 'red'}}>
<Text>OverlayStorybook</Text>
</View>
<View style={{flex: 1, backgroundColor: 'blue', top: 0}} />
</View>
);
};
import React from 'react';
import {View, Text} from 'react-native';
export const OverlayStorybook = () => {
return (
<View style={{flex: 1}}>
<View style={{height: 100, backgroundColor: 'red'}}>
<Text>OverlayStorybook</Text>
</View>
<View style={{flex: 1, backgroundColor: 'blue', top: -50}} />
</View>
);
};
您可以在底部看到 50 个白色像素。
解决方案
这是我想出的一个选项:https ://snack.expo.io/@zvona/full-flex
所以删除 flex 并放置绝对定位,然后添加 50(而不是减去它)。当然,“50”取决于您要放置的位置。因此,如果标题元素的高度发生变化,基本上很容易出错。
<View style={{position: 'absolute', backgroundColor: 'rgba(32, 32, 128, 0.8)', top: 50, left: 0, right: 0, bottom: 0}} />
</View>
推荐阅读
- java - Spring @Bean Name,不适用于@Qualifier
- javascript - 你怎么知道哪些网站是 HTML 和 JS 以及哪些网站是使用 React、Angular 等通过 JS 呈现的?
- javascript - 从 json 中删除编号的键
- python-3.x - 二叉搜索树获得 AttributeError 的主要乐趣:'BTreeWordFinder' 对象没有属性 'showDepth'
- c - 将录制的声音发送到云端
- sql-server - SSIS EncryptSensitiveWithUserKey 和有关包执行的文档
- csv - 将带有日期时间的 CSV 文件正确导入 SAS
- android - 如何修复“无法创建 com.example.todolist.ui.task.TaskViewModel 类的实例”
- django - 'poll_extras' 不是注册的标签库。但是我已经注册了
- amazon-web-services - 将标签/名称添加到 ECS 通过 Terraform 部署的 EC2 实例