【问题标题】:How to handle image with dynamically using react native如何使用本机反应动态处理图像
【发布时间】:2015-11-20 11:30:02
【问题描述】:

这是我的场景使用组件我正在显示 图片。

var ImageRender = React.createClass({
    render : function(){
       return (<View style={{marginLeft:15,marginRight:15}}>
                   <Image source={uri} style={{height:220}}/>
               </View>)
    }
});

如果我为图像指定宽度,那么我在 图像宽度不适合的另一种分辨率。如何 动态实现这个图像widt

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    首先获取设备尺寸...

    var Dimensions = require('Dimensions');
    var {
      width,
      height
    } = Dimensions.get('window');
    

    然后使用它们...

    var ImageRender = React.createClass({ render : function(){ return (<View style={{marginLeft:15,marginRight:15}}> <Image source={uri} style={{height:220, width:width}}/> </View>) } });
    

    【讨论】:

    • 感谢您的回答。它有效,但我收到一个错误,即 NSDictionary 类型的 JSON 值“{width=375}”无法转换为 NSNumber。如何使用本机反应将 json 对象转换为数字
    • 也许我不需要将值包含在自己的大括号中。尝试不
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 2021-12-26
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    相关资源
    最近更新 更多