【问题标题】:Internationalization with Titanium's ListViewTitanium 的 ListView 国际化
【发布时间】:2015-03-25 21:32:16
【问题描述】:

我从我的 ListView 项目中得到重复的值(就像文本上的文本)。

这是我的问题(我不确定图片是否会上传):

而我的 ListView 代码是:

  <ListView id="listView" defaultItemTemplate="template" onItemclick="menuOptions">

                <!-- The Templates tag sets the ListView's templates property -->
                <Templates>

                    <!-- Define your item templates within the Templates tags or use the
                         Require tag to include a view that only contains an ItemTemplate -->
                    <ItemTemplate name="template">
                        <ImageView bindId="pic" id="icon" />
                        <Label id="petLabel" />
                        <Label id="needleLable" />
                        <Label id="heightControl"/>
                    </ItemTemplate>

                </Templates>

                <ListSection>
                    <ListItem id="petLabel" val="mascota" pic:image="/images/menu/footprint.png"/>
                    <ListItem id="needleLable" val="vacuna" pic:image="/images/menu/pet.png"/>
                    <ListItem id="heightControl" val="estadistica" pic:image="/images/menu/pet.png"/>
                </ListSection>
       </ListView>

在我用于国际化的文件(平台/android/values-en 和 values-es)中,我得到了这个:

字符串.xml

<resources>
<!--Menu -->
    <string name="itemPet">Pet Profile</string>
    <string name="itemNeedle">Needle</string>
    <string name="itemHeight">Height Control</string>

</resources>

和价值观-es

<resources>
     <!--Menu -->
    <string name="itemPet">Mascota</string>
    <string name="itemNeedle">Ver Vacunas</string>
    <string name="itemHeight">Control de peso</string>


</resources>

最后是我调用要显示的文本的 .tss 文件:

'#petLabel':{   
    textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
    text:L('itemPet'),
    font:{
        fontSize:30, 
        fontWeight:'bold',
        fontFamily:'clear-sans.light'
    }
}

'#needleLable':{    
    textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
    text: L('itemNeedle'),   
    font:{
        fontSize:30, 
        fontWeight:'bold',
        fontFamily:'clear-sans.light'
    }
}

'#heightControl':{  
    textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
    text:L('itemHeight'),
    font:{
        fontSize:30, 
        fontWeight:'bold',
        fontFamily:'clear-sans.light'
    }   
}

我不知道为什么会这样,我尝试了很多东西都无法解决,任何想法都会有用。

谢谢。

附加信息:

当我单击 ListItem 时,我做了一个警报,该事件得到了该事件,警报返回:

{properties={height=100dp, accessoryType=0, textAlign=center, font={fontWeight=bold, fontSize=30, fontFamily=clear-sans.light}, title=Ver Vacunas, val=vacuna, id= needleLable}, pic={image=/images/menu/pet.png}}

标题显示正确的文字,但问题仍然存在。

【问题讨论】:

    标签: listview internationalization titanium


    【解决方案1】:

    这可能是布局问题。

    尝试在 ListView 和 ListSection 元素中指定 layout='vertical'。

    类似这样的:

    <ListView id="listView" defaultItemTemplate="template" onItemclick="menuOptions" layout='vertical'>
    ....
     <ListSection layout='vertical'>
    

    【讨论】:

    • 感谢您对 Funtik 的回答,我尝试在 ListView 和 ListSection 元素中指定 layout='vertical' 但不幸的是它不起作用
    【解决方案2】:

    我在官方文档中发现: http://docs.appcelerator.com/titanium/3.0/#!/guide/Localization

    您可以通过 XML 属性指定本地化。

    所以我修改了我的 .xml 代码:

        <ListView id="listView" defaultItemTemplate="template" onItemclick="menuOptions">
    
                    <!-- The Templates tag sets the ListView's templates property -->
                    <Templates>
    
                        <!-- Define your item templates within the Templates tags or use the
                             Require tag to include a view that only contains an ItemTemplate -->
                        <ItemTemplate name="template">
                            <ImageView bindId="pic" id="icon" />
                            <Label  bindId="label" id="petLabel" />
    
                        </ItemTemplate>
    
                    </Templates>
    
        <ListSection>
                        <ListItem label:text="L('itemPet')" val="mascota" pic:image="/images/menu/footprint.png"/>
                        <ListItem label:text="L('itemNeedle')" val="vacuna" pic:image="/images/menu/pet.png"/>
                        <ListItem label:text="L('itemHeight')" title="" val="estadistica" pic:image="/images/menu/pet.png"/>
    
        </ListSection>
           </ListView>
    

    现在它运行良好,这几个词创造了魔力:label:text="L('itemPet')"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 2015-08-31
      相关资源
      最近更新 更多