立场:React Native中的绝对问题

2024-02-17

我正在制作一个反应本机应用程序,其中有一个左侧和右侧部分。

左侧部分包括flex:0.7右侧部分包括flex:0.2.

在左侧部分内,我有一个容器,里面有一个ImageBackground https://reactnative.dev/docs/imagebackground看起来像一个电路骨架

在其中我需要将子组件放置在相应的位置。

预期结果:

我尝试过的事情:

纯HTML和CSS方式:(按预期工作)

.container {
  display: flex;
  flex: 1;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.leftSection {
  flex: 0.7;
}

.rightSection {
  flex: 0.2;
  background-color: #ccc;
}

.bgContainer {
  background-repeat: no-repeat;
  position: relative;
  margin: 0 auto;
}

.bg-img {
  display: block;
  width: 100%;
}

.coil {
  position: absolute;
  top: 49.55%;
  left: 24.3%;
  width: 17.4418605%;
}

.evaporator {
  position: absolute;
  top: 7.25%;
  left: 54.5%;
  width: 11.627907%;
}

.compressor {
  position: absolute;
  top: 53.15%;
  left: 59.2%;
  width: 13.0813953%;
}

.component img {
  display: block;
  width: 100%;
}
<div class="container">
  <div class="leftSection">
    <div class="bgContainer">
      <img src="https://i.stack.imgur.com/AfygH.png" class="bg-img" />
      <div class="component coil">
        <img src="https://i.stack.imgur.com/SKUms.png" alt="coil-image" />
      </div>
      <div class="component evaporator">
        <img src="https://i.stack.imgur.com/spv58.png" alt="evaporator-image" />
      </div>
      <div class="component compressor">
        <img src="https://i.stack.imgur.com/fzSaH.png" alt="compressor-image" />
      </div>
    </div>
  </div>
  <div class="rightSection">
    Right Section
  </div>
</div>

但是当我在反应本机应用程序中执行此操作时,我尝试将其更改为反应本机就像,

import React from 'react';
import { View, Image, StyleSheet, Text, ImageBackground } from 'react-native';

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'space-between',
    alignItems: 'center',
  },
  leftSection: {
    flex: 0.7,
  },
  rightSection: {
    flex: 0.2,
    backgroundColor: '#ccc',
  },
  bgContainer: {
    position: 'relative',
    margin: 0,
  },
  bgImg: {
    width: '100%',
  },
  coil: {
    position: 'absolute',
    top: '49.55%',
    left: '24.3%',
    width: '17.4418605%',
  },
  evaporator: {
    position: 'absolute',
    top: '7.25%',
    left: '54.5%',
    width: '11.627907%',
  },
  compressor: {
    position: 'absolute',
    top: '53.15%',
    left: '59.2%',
    width: '13.0813953%',
  },
  componentImg: {
    width: '100%',
  },
});

const App = () => {
  return (
    <View style={styles.container}>
      <View style={styles.leftSection}>
        <View style={styles.bgContainer}>
          <ImageBackground
            source={{ uri: 'https://i.stack.imgur.com/AfygH.png' }}
            style={styles.bgImg}
          >
          <View style={styles.coil}>
            <Image
              source={{ uri: 'https://i.stack.imgur.com/SKUms.png' }}
              style={styles.componentImg}
            />
          </View>
          <View style={styles.evaporator}>
            <Image
              source={{ uri: 'https://i.stack.imgur.com/spv58.png' }}
              style={styles.componentImg}
            />
          </View>
          <View style={styles.compressor}>
            <Image
              source={{ uri: 'https://i.stack.imgur.com/fzSaH.png' }}
              style={styles.componentImg}
            />
          </View>
          </ImageBackground>
        </View>
      </View>
      <View style={styles.rightSection}>
        <Text>Right Section</Text>
      </View>
    </View>
  );
};

export default App;

Issue:

实施后,

下面的屏幕截图是在屏幕视口中捕获的身高:844 and 宽度:1280

下面的屏幕截图是在屏幕视口中捕获的身高:552 and 宽度:1024

我主要为所有高度和宽度的平板电脑屏幕制作此内容,但以纯 HTML 和 CSS 方式,这是响应式的,但在反应本机的平板电脑屏幕中,它根本不响应。

请帮我解决这个制作问题position:absolute元素响应灵敏并且位于所有屏幕上的相同位置,没有失真。

Note:编辑我的问题以提及此实现是在反应本机中发生的。


尝试这个:

.container {
    background-image: url('https://i.stack.imgur.com/AfygH.png');
    height: 400px;
    background-position: center;
    background-size: contain;
    width: 700px;
}
.coil {
    position: absolute;
    top: 204px;
    left: 180px;
    zoom: 101%;    }
.evaporator {
    position: absolute;
    top: 26px;
    left: 320px;
    zoom: 121%;
}
.compressor {
    position: absolute;
    top: 220px;
    left: 422px;
    zoom: 100%;
}
<div class="container">
  <div class="coil">
    <img src="https://i.stack.imgur.com/SKUms.png" alt="coil-image" />
  </div>
  <div class="evaporator">
    <img src="https://i.stack.imgur.com/spv58.png" alt="evaporator-image" />
  </div>
  <div class="compressor">
    <img src="https://i.stack.imgur.com/fzSaH.png" alt="compressor-image" />
  </div>
</div>;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

立场:React Native中的绝对问题 的相关文章

随机推荐

  • json数组:如何创建新的数组元素?

    我的目标是得到一个像这样的 json 数组 var args name test value 1 key test2 value 2 我怎样才能得到下面的代码来构建像上面一样的数组 this dependentProperties arra
  • “read/1”调用后 SWI Prolog 回溯行为

    我在看另一个序言 https stackoverflow com questions 47317413 how to use user input in prolog to search在StackOverflow上提问并遇到这种情况 假设
  • 音隙不起作用

    我已经从其网站下载了phonegap示例 但它没有运行 我找不到原因 请帮助我获得解决方案 当我运行时它显示 无法加载位于 file andriod asset www index html 的网页 找不到所请求的文件 www index
  • 如何将SIRI集成到iPhone应用程序中? [关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 我正在开发一个 iPad 应用程序
  • 如何在 jQuery Ajax 成功回调中处理我的 JSON 数据?

    如果我有一个ajax调用 ajax url url dataType json data data success function json data What s the efficient way to extract the JSO
  • Babel:ES6 中的函数参数类型

    如果我编写以下代码并将其转译为通天塔 6 5 0 它工作正常 function foo first string second number code here string and number刚刚从转译的 ES5 代码中删除 如果我使用
  • C#、F#、IronPython 和 IronRuby 的集成

    有人告诉我 由 C 和 F 源代码生成的程序集文件是可以互操作的 因为它们被编译成 NET 程序集 Q1 这是否意味着 C 可以像调用 C 函数一样调用 F 函数 Q2 IronPython 和 IronRuby 怎么样 我没有看到来自 I
  • 一个或多个数组的加权洗牌?

    使用嵌套数组中的权重对一个或多个数组进行混洗的好算法是什么 Example array array array name gt John rank gt 3 array name gt Bob rank gt 1 array name gt
  • 判断 __getattr__ 是方法还是属性调用

    有什么方法可以使用 getattr 确定方法和属性调用之间的区别吗 I e in class Bar object def getattr self name if THIS IS A METHOD CALL Handle method c
  • 如何在 Google AppEngine 平台上访问 Fauxton?

    我正在 Google App Engine 上创建一个离线优先的应用程序 其中 PouchDB 作为我的本地数据库 CouchDB 作为我的远程数据库 我已在 Google AppEngine 上启用了 CouchDB 并尝试访问以下 UR
  • 今天小部件在应用程序更新后没有响应

    我今天的小部件有一个奇怪的案例 我的应用程序有一个小部件来向用户显示一些信息 小部件上有一些按钮 用户可以点击按钮来获取不同的信息 奇怪的是 我正在开发我的应用程序的新版本 我需要测试一下 当我在旧版本上安装新的临时版本应用程序时 我的小部
  • Python f.write() 不接受更多参数

    我有这样的Python代码 f open nv csv a a 10 3 b 3 12 c 3 13 f write a b c 这将输出返回为 f write a b c TypeError function takes exactly
  • 如何在 PHP 中将字符串转换为数字?

    我想转换这些类型的值 3 2 34 0 234343 等到一个数字 在 JavaScript 中我们可以使用Number 但是PHP中有类似的方法吗 Input Output 2 2 2 34 2 34 0 3454545 0 345454
  • 如何使用React Router将数据从一个页面传递到另一个页面

    请我需要有关react router dom的帮助 我是这个库的新手 似乎可以找到任何解决方案 我从 api 调用中得到三个结果 其中我映射数据以将其呈现在 UI 上 现在我需要的是 如果我单击此列表之一上的一行 我希望它带我到屏幕仅显示我
  • Calendar.WEEK_OF_MONTH 在两个不同的设备上给出不同的结果

    我有两台设备 HTC Android 2 3 5 和 Samsung Android 2 3 6 现在我面临的问题是 我需要日期是一个月中的第几周 所以我编写了这段代码并安装在两部手机上 并将系统日期设置为 2013年1月27日 Calen
  • 无法使用runtime.exec重新启动设备

    由于某种原因 我无法使用 Runtime getRuntime exec system bin reboot 重新启动 Android 设备 我已经在 3 台设备上尝试了以下代码 但没有成功 一个是从 rowboat android 源代码
  • 如何使用触控板在 Java AWT ScrollPane 中进行水平鼠标滚轮滚动

    与许多现代鼠标和触控板一样 我的笔记本电脑支持垂直和水平滚动 一旦你习惯了 它就会让人上瘾 我只是希望我的 Java 应用程序支持通过触控板 鼠标滚轮进行水平滚动 但在我搜索的所有地方似乎这在 Java 中是不可能的 我真的希望有人告诉我我
  • 使用内存中查询实现自定义 QueryProvider

    我正在尝试创建一个包装器可查询库 https github com re motion Relinq blob develop Core QueryableBase cs and INh查询提供者 https github com nhib
  • iOS 下载和解析大型 JSON 响应导致 CFData(存储)泄漏

    用户第一次打开我的应用程序时 我需要下载大量数据 我从服务器以 JSON 形式获取所有这些数据 根据用户的不同 这些 JSON 文件的大小可以从 10kb 到 30mb 不等 而且数量超过 10 个 当 JSON 的记录不超过 500 条左
  • 立场:React Native中的绝对问题

    我正在制作一个反应本机应用程序 其中有一个左侧和右侧部分 左侧部分包括flex 0 7右侧部分包括flex 0 2 在左侧部分内 我有一个容器 里面有一个ImageBackground https reactnative dev docs