您的位置:首页 > 移动开发 > Android开发

Titanium tableview android 和 ios 下拉刷新(pull to refresh )

2017-03-27 17:40 453 查看
#====================== 主布局 =================================

wrapper = Ti.UI.createScrollView

showVerticalScrollIndicator: true

showHorizontalScrollIndicator: false

width: Ti.UI.FILL

top: 0

bottom: if Ti.App.is_android then __l(54) else null

scrollingEnabled: if Ti.App.is_android then false else true

table_view = Ti.UI.createTableView

width: '100%'

backgroundColor: '#fff'

#bottom: if Ti.App.is_android then __l(54) else null

data: table_data

table_header = Ti.UI.createView

backgroundColor: "#f6f6f6"

width : Ti.App.platform_width

height : __l(60)

textAlign : 'center'

status_label_of_table_header = Ti.UI.createLabel

text : "下拉可以刷新..."

width : __l(200)

bottom : __l(15)

height : __l(17)

color : "#576c89"

textAlign : 'center'

textAlign : "center"

font :

fontSize : __l(12)

table_header.add status_label_of_table_header

table_view.headerPullView = table_header

pull_to_get_data =(callback) ->

get_data()

callback()

pulling = false
#====================== ios 下拉刷新 =================================

table_view.addEventListener 'scroll', (e) ->

console.info "=======  in table_view, scroll event"

if (Ti.App.is_android)

return

offset = e.contentOffset.y

if (offset <= -65.0 && !pulling)

pulling = true

status_label_of_table_header.text = "释放即可更新..."

else

if pulling && offset > -65.0 && offset < 0

pulling = false

status_label_of_table_header.text = "下拉可以刷新..."

table_view.addEventListener "dragend", (e) ->

if pulling

table_view.setContentInsets

top : __l(60)

animated : true

pull_to_get_data ->

status_label_of_table_header.text = "下拉可以刷新..."

table_view.setContentInsets

top : __l(0)

animated : true

return

pulling = false

return

#====================== android 下拉刷新 =================================
if Ti.App.is_android

swipeRefreshModule = require 'com.rkam.swiperefreshlayout'

swipeRefresh = swipeRefreshModule.createSwipeRefresh

view: table_view

#bottom: __l(54)

height: Ti.UI.FILL

width: Ti.UI.FILL

table_view.bottom = 0

swipeRefresh.addEventListener 'refreshing', ->

pull_to_get_data ->

swipeRefresh.setRefreshing(false)

return

wrapper.add swipeRefresh

change_record_win.add wrapper

else

#wrapper.add table_view

change_record_win.add table_view

wrapper = Ti.UI.createScrollView({
showVerticalScrollIndicator: true,
showHorizontalScrollIndicator: false,
width: Ti.UI.FILL,
top: 0,
bottom: Ti.App.is_android ? __l(54) : null,
scrollingEnabled: Ti.App.is_android ? false : true
});
table_view = Ti.UI.createTableView({
width: '100%',
backgroundColor: '#fff',
data: table_data
});
table_header = Ti.UI.createView({
backgroundColor: "#f6f6f6",
width: Ti.App.platform_width,
height: __l(60),
textAlign: 'center'
});
status_label_of_table_header = Ti.UI.createLabel({
text: "下拉可以刷新...",
width: __l(200),
bottom: __l(15),
height: __l(17),
color: "#576c89",
textAlign: 'center',
textAlign: "center",
font: {
fontSize: __l(12)
}
});
table_header.add(status_label_of_table_header);
table_view.headerPullView = table_header;
pull_to_get_data = function(callback) {
get_data();
return callback();
};
pulling = false;

table_view.addEventListener('scroll', function(e) {

var offset;

console.info("=======  in table_view, scroll event");

if (Ti.App.is_android) {

return;

}

offset = e.contentOffset.y;

if (offset <= -65.0 && !pulling) {

pulling = true;

return status_label_of_table_header.text = "释放即可更新...";

} else {

if (pulling && offset > -65.0 && offset < 0) {

pulling = false;

return status_label_of_table_header.text = "下拉可以刷新...";

}

}

});

table_view.addEventListener("dragend", function(e) {

if (pulling) {

table_view.setContentInsets({

top: __l(60),

animated: true

});

pull_to_get_data(function() {

status_label_of_table_header.text = "下拉可以刷新...";

table_view.setContentInsets({

top: __l(0),

animated: true

});

});

pulling = false;

}

});

if (Ti.App.is_android) {

swipeRefreshModule = require('com.rkam.swiperefreshlayout');

swipeRefresh = swipeRefreshModule.createSwipeRefresh({

view: table_view,

height: Ti.UI.FILL,

width: Ti.UI.FILL

});

table_view.bottom = 0;

swipeRefresh.addEventListener('refreshing', function() {

return pull_to_get_data(function() {

swipeRefresh.setRefreshing(false);

});

});

wrapper.add(swipeRefresh);

change_record_win.add(wrapper);

} else {

change_record_win.add(table_view);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐