针对不同屏幕尺寸定位钛合金小部件时出现问题



点击这里!查看在Nexus 5和Galaxy Core上拍摄的屏幕截图...在银河核心中,一切看起来都很好,但在 nexus 5 中,由于屏幕尺寸不同,小部件会向左移动......我已经设定了

<property name="ti.ui.defaultunit" type="string">dp</property> 

在我的提亚普.xml

我的 xml 文件如下...

<Alloy>
<Window  id='PreferenceScreen' >
    <Button id='button_save' title="Save"/>
    <Label  id='label_my_project' >My project</Label>
    <Label  id='label_select_city' >
    </Label>
    <Label  id='label_select_locality' >
    </Label>
</Window>
</Alloy>

----我的 tss 文件----

'#label_my_project': {
top: '88',
left: '20',
width: '280',
backgroundColor: '#00aac1',
color: '#ffffff',
text: 'My Project',
textAlign: 'center',
font: {
    fontSize: '25sp'
}
},
'#label_select_city[platform=android]': {
hintText: 'Select City'
},
'#label_select_city': {
top: '143',
left: '40',
width: '240',
font: {
    fontSize: '20sp'
}
},
'#label_select_locality[platform=android]': {
hintText: 'Select Locality'
},
'#label_select_locality': {
top: '214',
left: '40',
width: '240',
font: {
    fontSize: '20dpsp'
}
},
'#button_save': {
top: '293',
left: '58',
width: '200',
borderWidth: 1,
borderRadius: 5,
borderColor: '#fff',
backgroundColor: '#00aac1',
backgroundSelectedColor: '#fff',
color: '#ffffff',
selectedColor: '#00aac1',
textAlign: 'center',
font: {
    fontSize: '20sp'
}
},
'#PreferenceScreen[platform=android]': {
fullscreen: false
},
'#PreferenceScreen': {
top: '0',
left: '0',
backgroundColor: '#00aac1',
navGroup: ''
},

我也尝试过%但结果相同

请帮忙,因为我从过去两天一直被困,仍然没有解决方案......

你想居中所有元素吗?只需使用

width:'auto' 

在所有标签上,然后制作首选项屏幕

Ti.UI.FILL

试试这个代码:

视图:

<Alloy>
<Window  id='PreferenceScreen' >   
    <View id='container'>
        <Label  id='label_my_project' >My project</Label>
        <Label  id='label_select_city' >
        </Label>
        <Label  id='label_select_locality' >
        </Label>
         <Button id='button_save' title="Save"/>
     </View>
</Window>
</Alloy>

TSS:

'#label_my_project': {
    //top: '88',
    //left: '20',
    width: '280',
    backgroundColor: '#00aac1',
    color: '#ffffff',
    text: 'My Project',
    textAlign: 'center',
    font: {
        fontSize: '25sp'
    }
},
'#label_select_city[platform=android]': {
    hintText: 'Select City'
},
'#label_select_city': {
    top: '40dp',
    //left: '40',
    width: '240',
    backgroundColor:'white',
    font: {
        fontSize: '20sp'
    }
},
'#label_select_locality[platform=android]': {
    hintText: 'Select Locality'
},
'#label_select_locality': {
    top: '40dp',
    //left: '40',
    width: '240',
    backgroundColor:'white',
    font: {
            fontSize: '20dpsp'
    }
},
'#button_save': {
    //left: '58',
    top:'40dp',
    width: '200',
    borderWidth: 1,
    borderRadius: 5,
    borderColor: '#fff',
    backgroundColor: '#00aac1',
    backgroundSelectedColor: '#fff',
    color: '#ffffff',
    selectedColor: '#00aac1',
    textAlign: 'center',
    font: {
        fontSize: '20sp'
    }
},
'#PreferenceScreen[platform=android]': {
    fullscreen: false
},
'#PreferenceScreen': {
    top: '0',
    left: '0',
    width:Ti.UI.fill,   
    height:Ti.UI.FILL,
    backgroundColor: '#00aac1',
    navGroup: ''
},
"#container":{
    layout:'vertical',
    height:Ti.UI.SIZE,
}

最新更新