不同Android版本的图像渲染差异

Ped*_*ves 8 css html5 android image sencha-touch-2

我正在尝试使用Sencha Touch构建图库.我创建了一个容器对象,其hbox布局和宽度等于window.innerWidth.然后,我在里面添加三个容器.每个使用vbox布局,宽度等于window.innerWidth/3.

我在其中添加宽​​度等于CSS上设置的列宽和高度的图像为'auto'.

这是我的代码:

Ext.define('Oasis.view.ImgTest',{
extend: 'Ext.Container',
xtype:'mosaic',
config:{
    cls: 'gallery',
    layout: {
        type: 'hbox', // This is a column-based mosaic
        pack: 'center',
        align: 'start'
    },
    columnWidth: -1,//
    numCols: 3, // Number of columns
    lastColumnUsed: -1, // Last column where a image were added. -1 for none.
    autoInstanceColumns: false, // If true, instantiate each column on initialize method
    items:[],
    scrollable: {
        direction: 'vertical',
        directionLock : true
    }
},
initialize: function(){
    var me = this;

    me.setColumnWidth(window.innerWidth/me.getNumCols());

    Ext.Viewport.on('orientationchange', function(){
        // Updates columns widths on screen orientation changes
        me.setColumnWidth(window.innerWidth/me.getNumCols());
        for(var c = 0; c < me.getNumCols();c++){
            // Column
            var column = me.getAt(c);
            for(var i = 0; i < column.getItems().getCount();i++){
                // Items per column
                var element = column.getAt(i);
                element.setWidth(me.getColumnWidth());
            }
        }
    }, this, {buffer: 50 });

    // Creates all columns and add to the mosaic
    if(me.getAutoInstanceColumns())
        for(var i = 0; i < me.getNumCols();i++){
            me.add({
                xtype:'container',
                id: 'col-'+i,
                cls: 'gallery',
                layout: 'vbox',
                flex:1
            });
        }


    // Add images
    me.insert(Ext.create('Ext.Img',{
            src:'resources/images/0228_FEA_Pet_dog_WCGHS_cutt.jpg',
            cls: 'mosaicitem',
            mode: 'element'
        }));me.insert(Ext.create('Ext.Img',{
            src:'resources/images/027c076a1c-1152x864.jpg',
            cls: 'mosaicitem',
            mode: 'element'
        }));me.insert(Ext.create('Ext.Img',{
            src:'resources/images/0913_LIF_PET_DOG_CUTTY_WCG.jpg',
            cls: 'mosaicitem',
            mode: 'element'
        }));
},
__get_next_column_index: function(){
    var me = this;
    var column = 0;

    // If some column was used in the last iteraction (if there was one),
    // calculates the next column that should be used. Else, use column 0.
    if(me.getLastColumnUsed() >= 0){
        column = (me.getLastColumnUsed() + 1) % me.getNumCols();
    }


    return column
},
insert: function(element){
    var me = this;

    // Se as colunas não forem instanciadas logo na initialização da classe, instancia uma a uma até que todas estejam instanciadas.
    if(!me.getAutoInstanceColumns() && me.getItems().getCount() < me.getNumCols()){
        var column = me.getItems().getCount();
        target_column = me.add({
                xtype:'container',
                id: 'col-'+column,
                cls: 'column',
                flex:1
            });
    }else{
        var column = me.__get_next_column_index();
        var target_column = me.getAt(column);
    }   

    // Set element width
    element.setWidth(me.getColumnWidth());
    target_column.add(element);
    me.setLastColumnUsed(column);
},
Run Code Online (Sandbox Code Playgroud)

})

这是我的CSS:

.gallery {
line-height: 0;
-webkit-column-gap: 0px;
margin: 2px 2px 2px 2px;
height: 100%;
}
.mosaicitem {
height:auto !important; 
border: 2px solid rgba(0,0,0,0.4);
border-radius: 5px;
padding: 2px;
background: rgba(0,0,0,0.5);
position: relative;
-webkit-animation: fadein 1s, translateZ 0.6s; /* Safari and Chrome */
-webkit-animation-delay: 0s, 0s;
   -moz-animation: fadein 1s, translateZ 0.6s; /* Firefox */
   -moz-animation-delay: 0s, 0s;
    -ms-animation: fadein 1s, translateZ 0.6s; /* Internet Explorer */
    -ms-animation-delay: 0s, 0s;
     -o-animation: fadein 1s, translateZ 0.6s; /* Opera */
     -o-animation-delay: 0s, 0s;
        animation: fadein 1s, translateZ 0.6s;
        animation-delay: 0s, 0s;
}

/* Animations */
@keyframes fadein {
from { opacity: 0 ; }
to   { opacity: 1 ; }
}
@keyframes translateZ {
from { top : 100px ; }
to   { top: 0px ; }
}

/* Firefox */
@-moz-keyframes fadein {
from { opacity: 0 ; }
to   { opacity: 1 ; }
}
@-moz-keyframes translateZ {
from { top : 100px ; }
to   { top: 0px ; }
}

/* Safari and Chrome */
@-webkit-keyframes fadein {
from { opacity: 0 ; }
to   { opacity: 1 ; }
}

@-webkit-keyframes translateZ {
from { top : 100px ; }
to   { top: 0px ; }
}

/* Internet Explorer */
@-ms-keyframes fadein {
from { opacity: 0 ; }
to   { opacity: 1 ; }
}?
@-ms-keyframes translateZ {
from { top : 100px ; }
to   { top: 0px ; }
}

/* Opera */
@-o-keyframes fadein {
from { opacity: 0 ; }
to   { opacity: 1 ; }
}?
@-o-keyframes translateZ {
from { top : 100px ; }
to   { top: 0px ; }
}
Run Code Online (Sandbox Code Playgroud)

在运行android 4.4.2的设备上,它运行得很好.但是,在Android 4.2.2上,它看起来好像高度设置为100%或类似的东西.

这是Android模拟器上的比较. 在此输入图像描述

这里发生了什么事?

Saf*_*ron 5

mosaicitem在你的CSS类设置的height是属性auto.这意味着您让浏览器重新调整图像.显然,您将在不同的浏览器上获得不同的结果.我不确切知道两个浏览器对你的设置有何反应,但它只能来自这个.

取自Sencha关于该Ext.Image height物业的Doc :

默认情况下,如果未明确设置此元素,则此Component的元素将具有其自己的自然大小.

所以我相信这条线用你的!重要标签强加了一个高度,并覆盖了sencha的自动高度,这应该是图像的自然大小.

简而言之,请尝试删除此行.