- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我必须实现一个画廊,它可以移动到下一张带有动画的幻灯片。我在这里找到了一些解决方案: How to have scrolling animation programmatically
我正在使用这段代码:
//scroll forward or backward
private void scroll(int type){
View selectedV = mG.getSelectedView();
int idx = mG.indexOfChild(selectedV);
switch(type){
case FORWARD:
default:
if(idx<mG.getChildCount()-1)
idx++;
break;
case BACKWARD:
if(idx>0)
idx--;
break;
}
//now scrolled view's child idx in gallery is gotten
View nextView = mG.getChildAt(idx);
//(x,y) in scrolled view is gotten
int x = nextView.getLeft()+nextView.getWidth()/2;
int y = nextView.getTop()+nextView.getHeight()/2;
String out = String.format("x=%d, y=%d", x, y);
Log.i(TAG+".scroll", out);
//Kurru's simulating clicking view
MotionEvent event = MotionEvent.obtain(100, 100, MotionEvent.ACTION_DOWN, x, y, 0);
mG.onDown(event);
boolean res = mG.onSingleTapUp(null);
Log.i(TAG+".scroll", "onSingleTapUp return =" + res);
问题是它只有在我有 3 张图像可见时才有效,而且显然它甚至在某些设备上也不起作用。
但是,当我一次显示一张图片时(它们几乎占据了设备的所有宽度),此方法不起作用。这就是我实现以下方法的原因:
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if(e1 == null || e2 == null) return false;
if (isScrollingLeft(e1, e2)) { // Check if scrolling left
if(State.curentZoom==0)
return super.onFling(e1, e2, State.imgWidthBig*1.1f, 0);
else {
scroll(BACKWARD);
return true;
}
} else if (isScrollingRight(e1, e2)) { // Otherwise scrolling right
if(State.curentZoom==0)
return super.onFling(e1, e2, (-1)*State.imgWidthBig*1.1f, 0);
else {
scroll(FORWARD);
return true;
}
} else
return false;
}
使用其他帖子中的代码: How to stop scrolling in a Gallery Widget?
目标:计算正确的 velocityX,以便从一张幻灯片向左或向右平滑滚动到另一张幻灯片。速度以像素/秒计算。如果我提供的速度太小,那么图像会滚动一点并返回到前一个。如果速度太大,那么它会滚动多个图像,但我需要它一张一张地滚动到下一张/上一张图像,即使距离很小。我发现尝试时,最佳值略大于设备宽度,但我想知道是否所有设备都是这种情况。
最佳答案
聚会有点晚了。 AOSP 提供了 2 个类来帮助您计算速度,VelocityTracker
和 ViewConfiguration
。跟踪器消耗 MotionEvents 并输出 X/Y 速度。而 ViewConfiguration 声明了不同手势类型的阈值。
下面是一个使用这 2 个类来检测滑动手势的简单示例。
mVelocityTracker = VelocityTracker.obtain();
mViewConfiguration = ViewConfiguration.get(mContext);
mListView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int action = event.getActionMasked();
mVelocityTracker.addMovement(event);
if (action == MotionEvent.ACTION_UP) {
mVelocityTracker.computeCurrentVelocity(1000, mViewConfiguration.getScaledMaximumFlingVelocity());
if (mVelocityTracker.getXVelocity() > mViewConfiguration.getScaledMinimumFlingVelocity()) {
// horizontal fling!
return true;
}
}
return false;
}
});
关于安卓图库一掷千金 : how to calculate the necessary velocity for a fling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12405960/
有没有办法在 Velocity 中做三元运算符? 这就是我想做的: #set ($name = ($args.get(0) == "") ? "default" : $args.get(0)) 而不是
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 4年前关闭。 Improve this qu
我有一个 Java 数组,例如: String[] arr = new String[] {"123","doc","projectReport.doc"}; 在我看来,访问的自然方式是: #set
拥有: Velocity 模板或宏 某个物体 如何以易于追踪到失败位置(例如在 Java 中抛出异常)的方式验证对象 (#if) 并失败(停止进一步处理)。 我正在寻找这样的东西: #if ( ! $
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
在 xwiki 中使用 Apache velocity,如何像在 JavaScript 中那样创建一个 console.log()?我知道日志可能会在服务器端。我真的只想打印为调试目的而呈现的变量值。
我有一个 Velocity 模板文件,其中包含来自 XML 的数据。我想将字符串转换为整数类型。 我怎样才能做到这一点? 最佳答案 啊哈!去过那里。 #set($intString = "9") #s
您如何在 Velocity 中获得查询中第一项的输出。例如,如果您的查询是 $Items 并且包含许多对象,您如何获得第一个? 我试过 $Items(1) 但这不是答案。有什么建议?谢谢你。 最佳答案
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
是否可以通过名称调用速度宏,例如: #macro (sayHello) Hello! #end #set ($macroName = "sayHello") #$macroName() 谢谢! 最佳
我对在 if 语句中处理多个和/或语句感到有点困惑。我希望有人能帮我解决这个问题。 Velocity 引用指南似乎没有解决我正在尝试做的事情。 我正在使用一个应用程序,我将在其中使用公共(public
我在包含一些路径的速度模板中设置了一个数组。 这个想法是在这个数组中放置一些“默认”的 .js/.css 文件,90% 的页面将使用这些文件。 但是,其他页面仍然必须能够从该数组中添加/删除值,以防根
我试图通过在初始请求下载的 HTML 中内联一些 CSS 来优化一些移动网页(或更准确的服务器请求数量)。 这些页面来自我们基于 Vosao 的 CMS,并使用 Apache Velocity 宏。
如果在VelocityContext中没有找到值,Velocity只会打印标签名称,即我的模板文件中的$name,但是VelocityContext中没有“name”的值,所以只打印了“$name”。
Marketo 限制了 10 个最近的可搜索机会,不幸的是,我们有很多用户拥有超过 10 个机会。 foreach 循环似乎从最近最少更新的机会开始,并在列表中向上移动到最近更新的机会。这里的问题是,
如何在 Velocity 模板引擎中将十进制数四舍五入到 2 位? #set ($Percentage = $Marks*100/$Total) 我想将百分比四舍五入到小数点后两位。我怎样才能做到这一
我在扩展 AbstractProcessor 的注释处理器内初始化速度引擎,如下所示: public boolean process(Set annotations, RoundEnvironment
我有一个速度模板,它代表一个 XML 文件。我使用传递给 VelocityContext 对象的数据填充标签之间的文本。然后在模板中访问它。 这是一个例子,我们称之为 myTemplate.vm: $
我在linux下工作,在我的应用程序中,我限制了权限,所有路径都是只读的 在我的应用程序中,我使用了 velocity-1.6.2.jar 并且每次调用它时都会创建 velocity.log 并且该文
我正在尝试使用嵌入在 Atlassian 产品中的 Velocity 引擎(并通过 com.atlassian.templaterenderer 公开)将 JSON 值替换为模板。 在模板中,这看起来
我是一名优秀的程序员,十分优秀!