首页 \ 问答 \ 在Android中的GridLayout中重新排序项目的动画(Animating of reordering items in GridLayout in Android)

在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
更新时间:2022-01-27 21:01

最满意答案

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 (text)
         36 BUILD_TUPLE              2
         39 BINARY_MODULO       
         40 PRINT_ITEM          
         41 PRINT_NEWLINE       

如您所见,那里有两个打印字节码( PRINT_ITEMPRINT_NEWLINE )。 如果线程在两者之间被抢占,你会看到你所看到的。

我同意其他人的观点, sys.stdout.write()对于这个用例来说是一个更安全的赌注,因为:

  1. 它会强制你在编写之前格式化整个字符串(使用print可能会意外地使用print a, b, c,最后print a, b, c,三个单独的写入而不是一个);
  2. 它回避了软空间和自动换行的问题,两者都可以与程序其他部分的print语句进行交互。

print is not atomic.

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 and PRINT_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:

  1. it forces you to format the entire string before you write it (with print you can accidentally use print a, b, c, and end up with three separate writes instead of one);
  2. it sidesteps the issues of softspace and automatic newline, both of which can interact with print statements in other parts of the program.

相关问答

更多
  • 首先将所有数字存储在一个数组中。 稍后循环它。 而不是检查索引值,如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 = ...
  • 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()创建一个具有起始值和“步长”的函数对象,通过该“步骤”将增加 ...
  • 发生这种情况是因为您的第二个循环使用数组本身作为循环变量,覆盖最后一个值。 它应该是这样写的: 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)

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)