在Android中的GridLayout中重新排序项目的动画(Animating of reordering items in GridLayout in Android)
当我在GridLayout中添加或删除或重新排序项目时,在GridLayout中实现重新排序项目的动画的方法是什么?
例如
GirdLayout layout = findById(R.id.layout); layout.addView(someView,index); //and how to make items animated on reordering ?
感谢您的帮助或想法! 谢谢。
What is the way to implement animation of reordering items in GridLayout when I add or remove or reorder items in GridLayout?
For example
GirdLayout layout = findById(R.id.layout); layout.addView(someView,index); //and how to make items animated on reordering ?
Appreciate your help or ideas! Thanks.
原文:https://stackoverflow.com/questions/26254502
最满意答案
以下行:
print "%s :: %s" % (self.num, text)
被翻译成以下字节码:
24 LOAD_CONST 1 ('%s :: %s') 27 LOAD_FAST 0 (self) 30 LOAD_ATTR 3 (num) 33 LOAD_FAST 1 (text) 36 BUILD_TUPLE 2 39 BINARY_MODULO 40 PRINT_ITEM 41 PRINT_NEWLINE
如您所见,那里有两个打印字节码(
PRINT_ITEM
和PRINT_NEWLINE
)。 如果线程在两者之间被抢占,你会看到你所看到的。我同意其他人的观点,
sys.stdout.write()
对于这个用例来说是一个更安全的赌注,因为:
- 它会强制你在编写之前格式化整个字符串(使用
print a, b, c,
最后print a, b, c,
三个单独的写入而不是一个);- 它回避了软空间和自动换行的问题,两者都可以与程序其他部分的
The following line:
print "%s :: %s" % (self.num, text)
get translated into the following bytecodes:
24 LOAD_CONST 1 ('%s :: %s') 27 LOAD_FAST 0 (self) 30 LOAD_ATTR 3 (num) 33 LOAD_FAST 1 (text) 36 BUILD_TUPLE 2 39 BINARY_MODULO 40 PRINT_ITEM 41 PRINT_NEWLINE
As you can see, there are two printing bytecodes there (
PRINT_ITEM
andPRINT_NEWLINE
). If the thread gets preempted between the two, you would see what you are seeing.I agree with others that
sys.stdout.write()
is a safer bet for this use case since:
- it forces you to format the entire string before you write it (with
print a, b, c,
and end up with three separate writes instead of one);- it sidesteps the issues of softspace and automatic newline, both of which can interact with
相关问答
更多-
首先将所有数字存储在一个数组中。 稍后循环它。 而不是检查索引值,如if(i % 2 == 0 ) ,检查输入的数字if(numbers[i] % 2 == 0) 。 int[] numbers = new int[10]; //storing all the numbers in an array for(int i = 0; i < 10; ++i) numbers[i] = in.nextInt(); //checking each one for(int i = ...
-
为什么我的Python程序的输出看起来很奇怪?(Why does the output of my Python program look this (very odd) way?)[2022-05-30]
print不是原子的。 以下行: print "%s :: %s" % (self.num, text) 被翻译成以下字节码: 24 LOAD_CONST 1 ('%s :: %s') 27 LOAD_FAST 0 (self) 30 LOAD_ATTR 3 (num) 33 LOAD_FAST 1 ( ... -
通过分配值,您将定义新列表,而不是更新旧列表。 您可以使用它们上的id()函数进行检查。 By assigning a value, you are defining a new list, not updating the old one. You can check by using the id() function on them.
-
我假设你一直在保存ascii。 您可以修改您的C ++代码来编写二进制文件,并使用numpy.fromfile读取它。 要获得更直接的连接,您可以使用swig将C ++代码包装为库(删除main()并从Python驱动它)。 这允许您在C ++和Python之间共享数组的内存。 您可以在C ++端使用Python的缓冲区协议 ,在Python端使用numpy.frombuffer 。 或者您可以使用numpy标头直接在C ++中处理numpy数组。 这是一个使用第二种方法的小型swig示例项目 。 (免责声 ...
-
您需要添加一个处理程序来专门登录该文件。 import logging logger = logging.getLogger('myapp') hdlr = logging.FileHandler('/var/tmp/myapp.log') formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.set ...
-
你的缩进完全弄乱了程序。 最大的罪犯是这一部分: except IOError: print("Error reading file! Program ends here") endofprogram = True if (endofprogram == False): if行只会在endofprogram = True line之后立即执行,此时endofprogram == False将为false,因此if块中的任何内容 - 包括程序的其余部分 - 都将被执行。 你需要从if ...
-
看起来这就是发生的事情: http://rhodesmill.org/brandon/2010/ubuntu-exception-190-modules/ 基本上,apport模块(不是标准库的一部分)在异常写入stdout之前就会遇到极低的异常。 因此,当程序无法找到“herpaderp”时,它会抛出异常并触发导入apport及其包含的所有模块,并在异常之前将其显示在输出中。 解决方案? 我删除了“python-apport”包,以及依赖它的“ubuntuone-client”套件。 在卸载之后,异常就足 ...
-
函数makeInc()是一个“工厂”,它生成函数对象并返回它们。 nonlocal声明使函数“接近”变量。 通常你会创建一个显式变量并将其关闭; 在这种情况下,非本地声明正在关闭来自makeInc()的参数变量。 如果你想了解闭包和nonlocal这里有一些参考: http://www.mondoinfo.com/blog/C182263547/E20060918200706/index.html Python非本地语句 因此, makeInc()创建一个具有起始值和“步长”的函数对象,通过该“步骤”将增加 ...
-
奇怪的python数组输出(Weird output of python array)[2023-05-13]
发生这种情况是因为您的第二个循环使用数组本身作为循环变量,覆盖最后一个值。 它应该是这样写的: for x in arr: print x PS。 既然您刚刚开始使用Python:立即切换到Python 3! This happens because your second loop is using the array itself as the loop variable, overwriting the last value. It should have been written like ... -
你需要刷新标准输出: import time import sys while True: print("Hello!") sys.stdout.flush() time.sleep(1) You'll need to flush the stdout: import time import sys while True: print("Hello!") sys.stdout.flush() time.sleep(1)