【问题标题】:How make full screen image landscape orientation in react native?如何在本机反应中使全屏图像横向?
【发布时间】:2019-03-24 03:17:11
【问题描述】:

我对如何制作全屏图像横向方向很感兴趣,但没有高度:100%,所以宽度将是 100%,但高度是什么,因为在反应原生高度:不起作用=

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    这样试试

     <View style={{ flexDirection: 'row',}}>
          <Image
            style={{
            flex: 1,
            width: null,
            height: '100%',
            overflow: 'hidden',
         }}
         resizeMode='contain'
         source={{ uri: 'image path' }}
       />
    

    【讨论】:

    • 但我不想固定高度
    • 在 css 中给出高度为 100%
    • 它将在屏幕上全高......我不想要那个
    【解决方案2】:
    1. 首先,安装名为 @react-native-community/hooks 的包 ( npm i @react-native-community/hooks )
    2. 然后从上面的包中导入 useDimentions 和 useDeviceOrientation。 示例:从“@react-native-community/hooks”导入 {useDimentions,useDeviceOrientation } 像这样解构它们: 常量 { 横向,纵向 } = useDeviceOrientation(); 常量 { 屏幕,窗口 } = useDimensions(); 风景,肖像是布尔值 screen、window 是具有高度、宽度等的对象(通过console.log查看)
    3. 然后使用 screen.height 或 window.height 来获取设备的高度

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-23
      • 2018-09-16
      • 2016-08-13
      • 2020-05-14
      • 1970-01-01
      • 2021-05-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多