- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Titanium SDK 3.1.3 并将一个 Alloy 项目部署到 Android。我在一个名为 UserProfile 的 xml 文件中有一个窗口,如下所示:
<Alloy>
<Window class="container">
<View id="MainHolder">
<View id="MainHolderTitleView">
<View id="CloseButton">
<Label id="CloseButtonLabel"></Label>
</View>
<Label id="MainHolderTitleLabel"></Label>
<View id="CreatePostButton">
<ImageView id="CreatePostButtonImage" image="/images/menu_options.png"></ImageView>
</View>
</View>
<View id="AppSettings">
<View id="AppOptionButtons">
<View id="MenuOption1" class="optionButton">
<Label id="Option1Label" class="optionButtonLabel"></Label>
</View>
<View id="MenuOption2" class="optionButton">
<Label id="Option2Label" class="optionButtonLabel"></Label>
</View>
<View id="MenuOption3" class="optionButton">
<Label id="Option3Label" class="optionButtonLabel"></Label>
</View>
</View>
</View>
<View id="MainHolderWorkspace">
<TableView id="AppTableView"></TableView>
<ActivityIndicator id="activityIndicator"/>
</View>
</View>
</Window>
</Alloy>
tss 看起来像这样:
".container" : {
backgroundColor:"#b1b1b1",
width:Ti.UI.FILL,
height:Ti.UI.FILL,
top:0,
left:0,
navBarHidden : true
},
"#MenuAppsButton":{
height:'20dp'
},
"#MainHolderTitleLabel":{
// width : '250dp',
left : '60dp',
right : '60dp',
height : '25dp',
color:"#FFFFFF",
textAlign : 'center',
font:{fontSize:'12dp'},
ellipsize : true
},
"#CreatePostButton":{
right:0,
width:'44dp',
height:'44dp',
backgroundColor:"#242424"
},
"#CreatePostButtonImage":{
height:'20dp'
},
".optionButton":
{
width:Ti.UI.FILL,
height:'44dp',
backgroundColor:"#f0f0f0",
top:1
},
".optionButtonLabel":
{
color:"#363636",
font:{
fontSize:'12dp',
fontWeight:"bold"
},
height:Ti.UI.SIZE,
width:Ti.UI.SIZE
},
"#AppOptionButtons":
{
width:Ti.UI.FILL,
height:Ti.UI.SIZE,
backgroundColor:"transparent",
layout:"vertical"
},
"#AppSettings":
{
top:'44dp',
left:0,
backgroundColor:"transparent",
width:Ti.UI.FILL,
height:Ti.UI.FILL,
layout:"vertical"
},
"#MenuHolder":
{
width:Ti.UI.FILL,
height:Ti.UI.FILL,
top:0,
left:"-320dp",
zIndex:0,
backgroundColor:"#363636"
},
"#MainHolder":{
width:Ti.UI.FILL,
height:Ti.UI.FILL,
top:0,
left:0,
zIndex:1
},
"#MainHolderTitleView":
{
left:0,
right:0,
height:'44dp',
top:0,
backgroundColor:"#363636",
zIndex:0
},
"#MainHolderTitleDraggingView":
{
left:0,
width:'44dp',
height:'44dp',
top:0,
backgroundColor:"transparent",
zIndex:2
},
"#MainHolderWorkspace":
{
top:'44dp',
bottom:0,
left:0,
backgroundColor:"#b1b1b1",
zIndex:2
},
"#MainHolderTitleViewMenuButton":
{
width:'50dp',
height:'44dp',
left:0,
top:0,
backgroundColor:"#242424"
},
"#CloseButton":
{
width:'60dp',
height:Ti.UI.FILL,
backgroundColor:"#232323",
left:0
},
"#CloseButtonLabel":
{
color:"#FFFFFF",
font:{fontSize:'13dp'},
text : L('close_string')
},
"#AppTableView":
{
width:Ti.UI.FILL,
height:Ti.UI.SIZE,
top:0,
left:0,
showVerticalScrollIndicator:true,
backgroundGradient : {
type : 'linear',
colors : [
{
color : '#e7e7e7',
position : 0.0
},
{
color : '#d8d8d8',
position : 1.0
}
]
},
separatorColor : 'transparent'
},
"#activityIndicator":
{
width:Ti.UI.FILL
}
在我的表格 View 中,我添加了 2 行图像和 20 行更多的信息,这些信息是从网络服务获得的,这些行在开始时也包含图像。每次用户单击加载更多 View 时,都会添加 20 行更多信息,其中包含从网络服务获取的信息。
我添加的每一行都由不同的 View 组成,具体取决于从 Web 服务接收到的内容,唯一不变的是名为 Stream_Item 的 xml 中的 View ,如下所示:
<Alloy>
<View id="ContainerView" class="container">
<View id="GlobalWorkspace">
<View id="Workspace">
<View id="WorkspacePersonalInfo">
<View id="WorkspaceProfileImage">
<ImageView id="WorkspaceProfileImageView" image="/images/emptyPicture.png"></ImageView>
</View>
<View id="WorkspaceNameAndDateHolder">
<View id="WorkspaceNameTargetHolder">
<Label id="WorkspaceNameLastName"></Label>
<ImageView id="TargetImageView"></ImageView>
<Label id="WorkspaceTarget"></Label>
</View>
<Label id="WorkspaceDate"></Label>
</View>
</View>
<View id="WorkspaceContent"></View>
</View>
</View>
<View id="WorkspaceDecorator"></View>
</View>
</Alloy>
编辑 1这个 Controller 的代码如下所示: //获取传递给 Controller 的参数 var args = 参数[0] || {}; //加载脚本来处理图像缓存 var cacheImage = require('cacheImage'); //这是一个简单的还是复杂的条目 var simple = args.simple || 0;
//set values for this controller
$.WorkspaceNameLastName.text = args.user.name;
var created_at = args.created_at;
created_at = created_at.substring(0, created_at.indexOf('T'));
created_at = created_at.replace('-', '/');
created_at = created_at.replace('-', '/');
$.WorkspaceDate.text = created_at;
try
{
cacheImage('cachedImages_UserImages_Thumb', args.user.avatar.thumb, $.WorkspaceProfileImageView, null);
}
catch(error)
{
Ti.API.info(error);
}
//set correct width based on device screen
var workspaceWidth = Ti.Platform.displayCaps.platformWidth;
$.GlobalWorkspace.setWidth(workspaceWidth);
//if user pic is tapped, open profile
$.WorkspaceProfileImage.addEventListener("singletap", function(e) {
Alloy.createController("UserProfile", {
peopleObject:args.user
});
});
//arguments for like/dislike controller
var likenessArgs = {
data : args
};
//arguments for text controller
var textArgs = {
id : args.id,
text : L(args.action),
simple : true,
index : args.index,
simple : simple
};
//function to get the correct name of the class according to internationalization
function getClass(e)
{
switch(e)
{
case "Group":
return L('group_string');
case "Event":
return L('event_string');
case "Todo":
return L('todo_list_string');
case "TodoTask":
return L('todo_string');
case "Album":
return L('album_string');
case "AlbumPhoto":
return L('photo_string');
case "User":
return L('user_string');
}
}
//hide target user arrow image
$.TargetImageView.setOpacity(0);
//function to open viewer according to class
function openViewer(type)
{
switch(type)
{
case "User":
Alloy.createController("UserProfile", {
peopleObject : {
veramiko_id : args.target.veramiko_id
}
});
break;
case "Event":
Alloy.createController("Event_Details", {
evento : {
veramiko_id : args.target.veramiko_id
}
});
break;
case "Group":
Alloy.createController("Group_Profile", {
groupItem : {
veramiko_id : args.target.veramiko_id
}
});
break;
case "Album":
Alloy.createController("PhotoAlbumViewer", {
album : {
veramiko_id : args.target.veramiko_id
}
});
break;
}
}
//arguments for comments controller
var wall_posts_count = {};
wall_posts_count.wall_posts_count = parseInt(args.wall_posts_count);
wall_posts_count.id = args.id;
//variable to store attachment controller
var streamItemImageView;
//check if data received has a secondary target
if ( typeof args.secondary_target !== 'undefined')
{
//check if secondary target has a comment
if ( typeof args.secondary_target.comment !== 'undefined')
{
//construct the comment according to the context
var comment = args.secondary_target.comment;
textArgs.text = comment;
//check if user target is the same as logged user
if(args.target.veramiko_id !== Ti.App.Properties.getObject('loggedUser').user.veramiko_id)
{
if(args.target.veramiko_id !== args.user.veramiko_id)
{
//since there's a target display the necessary info for this target and the arrow target image
$.WorkspaceTarget.text = args.target.name;
$.WorkspaceTarget.width = $.WorkspaceTarget.toImage().width;
$.TargetImageView.image = Ti.Filesystem.resourcesDirectory + 'images/targetArrow.png';
$.TargetImageView.setOpacity(1);
$.WorkspaceTarget.addEventListener('singletap', function(e){
openViewer(args.target.class);
});
}
}
}
//check if there's an attachment
if ( typeof args.secondary_target.attachment !== 'undefined')
{
//create attachment controller
streamItemImageView = Alloy.createController("Stream_Item_Image", {
attachment : args.secondary_target.attachment,
comment : args.secondary_target.comment,
created_at : args.created_at,
updated_at : args.updated_at
}).getView();
$.WorkspaceContent.add(streamItemImageView);
}
}
// since there's no secondary target, it's a text post
else
{
var comment = args.target.name;
comment = "\"" + comment + "\"";
textArgs.text = textArgs.text + ': ' + comment;
}
// create like/dislike controller
var streamItemLikeDislikeView = Alloy.createController("Stream_Item_LikeDislike", likenessArgs);
// variable for user mentions in post
var streamItemMentions;
// check if there's any user mentions in this post
var mentionsArgs;
if(typeof args.mentions !== 'undefined')
{
// since there're user mentions, create the controller and the arguments for it
mentionsArgs = {
mentions : args.mentions
};
streamItemMentions = Alloy.createController("Stream_Item_Mentions", mentionsArgs);
}
// create comments controller
var streamItemCommentsView = Alloy.createController("Stream_Item_Comments", wall_posts_count);
// callback object with functions that update the comments count
var callbackObject = {};
callbackObject.increaseNumberOfComments = streamItemCommentsView.increaseNumberOfComments;
textArgs.callbacks = callbackObject;
// create text controller
var streamItemTextView = Alloy.createController("Stream_Item_Text", textArgs).getView();
$.WorkspaceContent.add(streamItemTextView);
//if there're user mentions, add the controller
if(typeof args.mentions !== 'undefined')
{
$.WorkspaceContent.add(streamItemMentions.getView());
}
// if it's a simple entry add the comments controller
if(args.simple)
{
$.WorkspaceContent.add(streamItemCommentsView.getView());
}
$.WorkspaceContent.add(streamItemLikeDislikeView.getView());
结束编辑 1
在 View WorkspaceContent 中添加了更多 View ,具体取决于是否已发表评论或是否已将图像附加到条目。
编辑 2此外,每个 Stream_Item Controller 都包含一个文本 Controller 和一个喜欢/不喜欢的 Controller ,这取决于条目是否有用户提及、附件和/或是否是一个简单的条目,添加额外的 Controller 。
我必须明确指出,这个 Stream_Item Controller 及其添加的 Controller 在其他 Windows 中工作得很好,但在这种特定类型的 Window 上它会出现错误。
结束编辑 2
我在 Android 中遇到的问题是行中包含的 View 上的触摸事件由于某种原因被阻止,我知道在处理 TableViews 时 Android 上的性能问题并在多个设备中进行测试后,除非具有触摸事件的元素已完成渲染,否则将允许用户与具有触摸事件的 View 进行交互。这只是一个猜测,但我认为在某种程度上对我的问题是准确的。我遇到的另一个问题是,在滚动或与表格的其他元素交互时,表格行中包含的图像有时会消失。
我不再使用 ScrollView 主要是因为向 TableView 添加元素的方法比 ScrollView 中的方法更实用(即能够在指定位置插入行,而 ScrollView 中没有这种行为)。我尝试了 List View,但 Alloy 中的实现非常困惑,文档也不清楚如何使用其他 Alloy View 动态更改内容。
有没有办法解决这些问题?我怎样才能让图像停止消失?我怎样才能绕过这个触摸 block ?
最佳答案
我对这个(消失的)问题也有非常糟糕的经历。由于 tableView 不像 iPhone 那样是 Android 的原生元素,这就是 Android 无法完美处理 TableView 并产生此类问题的原因。我多次遇到过这个问题。我建议你使用 ListView 而不是 TableView for android。只有这样我才能说你将能够避免这些问题。而对于触摸问题。我认为您需要直接在元素上使用 TouchEvents 而不是 View 。您如何使用 View 的 TouchEvents?
关于android - 如何在 Android 中使用钛合金修复 TableView 中消失的触摸事件和图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21034067/
我正在尝试将 WPF CodeBehid 事件(如 Event、Handler、EventSetter)转换为 MVVM 模式。我不允许使用 System.Windows.Controls,因为我使用
我可能误解了 Backbone 中的事件系统,但是当我尝试以下代码时什么也没有发生。当我向 Backbone.Events 扩展对象添加新属性时,它不应该触发某种更改、更新或重置事件吗?就像模型一样吗
我遇到了一个简单的问题,就是无法弄清楚为什么它不起作用。我有一个子组件“app-buttons”,其中我有一个输入字段,我想听,所以我可以根据输入值过滤列表。 如果我将输入放在我有列表的根组件中,一切
System.Timers.Timer 的 Elapsed 事件实际上与 System.Windows.Forms.Timer 的 Tick 事件相同吗? 在特定情况下使用其中一种比使用另一种有优势吗
嗨,这个 javascript 代码段是什么意思。(evt) 部分是如此令人困惑.. evt 不是 bool 值。这个怎么运作? function checkIt(evt) { evt
我正在使用jquery full calendar我试图在事件被删除时保存它。 $('calendar').fullCalendar ({
我有两个链接的鼠标事件: $('body > form').on("mousedown", function(e){ //Do stuff }).on("mouseup", function(
这是我的代码: $( '#Example' ).on( "keypress", function( keyEvent ) { if ( keyEvent.which != 44 ) {
我尝试了 dragOver 事件处理程序,但它没有正常工作。 我正在研究钢琴,我希望能够弹奏音符,即使那个键上没有发生鼠标按下。 是否有事件处理程序? 下面是我正在制作的钢琴的图片。 最佳答案 您应该
当悬停在相邻文本上时,我需要使隐藏按钮可见。这是通过 onMouseEnter 和 onMouseLeave 事件完成的。但是当点击另外的文本时,我需要使按钮完全可见并停止 onMouseLeave
我有ul标签内 div标签。我申请了mouseup事件 div标记和 click事件 ul标签。 问题 每当我点击 ul标签,然后都是 mouseup和 click事件被触发。 我想要的是当我点击 u
我是 Javascript 和 jQuery 的新手,所以我有一个非常愚蠢的疑问,请耐心等待 $(document).click(function () { alert("!"); v
我有一个邮政编码解析器,我正在使用 keyup 事件处理程序来跟踪输入长度何时达到 5,然后查询服务器以解析邮政编码。但是我想防止脚本被不必要地调用,所以我想知道是否有一种方法可以跟踪 keydown
使用事件 API,我有以下代码来发布带有事件照片的事件 $facebook = new Facebook(array( "appId" => "XXX", "se
首次加载 Microsoft Word 时,既不会触发 NewDocument 事件也不会触发 DocumentOpen 事件。当 Word 实例已打开并打开新文档或现有文档时,这些事件会正常触发。
我发现了很多相关问题(这里和其他地方),但还没有具体找到这个问题。 我正在尝试监听箭头键 (37-40) 的按键事件,但是当以特定顺序使用箭头键时,后续箭头不会生成“按键”事件。 例子: http:/
给定的 HTML: 和 JavaScript 的: var $test = $('#test'); $test.on('keydown', function(event) { if (eve
我是 Node.js 的新手,希望使用流运行程序。对于其他程序,我必须同时启动一个服务器(mongodb、redis 等),但我不知道我是否应该用这个运行一个服务器。请让我知道我哪里出了问题以及如何纠
我正在尝试使用 Swift 和 Cocoa 创建一个适用于 OS X 的应用程序。我希望应用程序能够响应关键事件,而不将焦点放在文本字段上/文本字段中。我在 Xcode 中创建了一个带有 Storyb
我有以下代码: (function(w,d,s,l,i){ w[l]=w[l]||[];w[l].push({
我是一名优秀的程序员,十分优秀!