旋转动画不会在中心点旋转资源(Rotation animation is not spinning the asset in center point)
按下时我正在尝试旋转圆形按钮。我的问题是按钮不会围绕它自己的中心旋转。 跟随其他例子但结果是一样的。 这是我的代码:
rotate.xml:
?xml version="1.0" encoding="utf-8"?>
<rotate android:duration="1500" android:interpolator="@android:anim/linear_interpolator" android:pivotX="50%" android:pivotY="50%" android:repeatCount="infinite" android:repeatMode="restart" android:toDegrees="360" />
在课堂上我正在使用动画:
Animation animRotate = AnimationUtils.loadAnimation(getContext(), R.animator.rotate); @Override public boolean onTouchEvent(MotionEvent event) { Log.e(TAG, "event:::" + event.getAction()); if (event.getAction() == MotionEvent.ACTION_DOWN) { view.startAnimation(animRotate); view.setBackgroundResource(R.drawable.some_asset); } else if (event.getAction() == MotionEvent.ACTION_UP ) { view.clearAnimation(); view.setBackgroundResource(R.drawable.some_asset); }
谢谢!
I'm trying to rotate a round button when is pressed.My problem is the button doesn't rotate around it's own centre. Followed other examples but the outcome is the same. Here is my code:
rotate.xml:
?xml version="1.0" encoding="utf-8"?>
<rotate android:duration="1500" android:interpolator="@android:anim/linear_interpolator" android:pivotX="50%" android:pivotY="50%" android:repeatCount="infinite" android:repeatMode="restart" android:toDegrees="360" />
and in the class I'm using the animation:
Animation animRotate = AnimationUtils.loadAnimation(getContext(), R.animator.rotate); @Override public boolean onTouchEvent(MotionEvent event) { Log.e(TAG, "event:::" + event.getAction()); if (event.getAction() == MotionEvent.ACTION_DOWN) { view.startAnimation(animRotate); view.setBackgroundResource(R.drawable.some_asset); } else if (event.getAction() == MotionEvent.ACTION_UP ) { view.clearAnimation(); view.setBackgroundResource(R.drawable.some_asset); }
Thank you!
原文:https://stackoverflow.com/questions/29942492
更新时间:2022-09-20 22:09
最满意答案
您可以使用列表理解:
tarfiles = [fname for fname in dirlist if fname.endswith(('.tgz','.tar'))]
要打印文件名,请使用
print "\n".join(tarfiles)
要么
for fname in tarfiles: print fname
You can use a list comprehension:
tarfiles = [fname for fname in dirlist if fname.endswith(('.tgz','.tar'))]
to print the filenames, use
print "\n".join(tarfiles)
or
for fname in tarfiles: print fname
相关问答
更多-
问题在于您在此行中初始化new_list的方式: new_list = list(list_init) 你的list_init设置为'test' ,所以当你创建new_list ,它看起来像 ['t', 'e', 's', 't'] 然后,如果base_list的长度> 4,则您尝试在索引5处将元素分配给new_list ,并获取IndexError 。 您应该像这样创建new_list : new_list = [None] * len(base_list) 这样,您可以确保new_list与new ...
-
您的问题看起来很糟糕,并且您正在简化太多......代码应该考虑到时间可用性以及成员资格。 忽略这个问题,选择/ 3而不是member / 2可以帮助建模一个天真的解决方案: schedule([],_,[]). % peek a suitable task for PersonId schedule([PersonId|People], Tasks, [[PersonId, TaskId]|RestOfAssignments]):- select(TaskId, Tasks, RestTasks), ...
-
你应该在找到第一个空位后退出循环: public void add(String s) { for(int i=store.length-1; i>=0; i--) { // note the change in the starting index if(store[i]==null) { store[i] = s; break; } } } You should exit the loop after ...
-
使用一个变量来保存总数,并在循环中更新它 totals = [0]*5 for i in range(5): l = list(range(5)) totals = [x + y for x, y in zip(totals, l)] print totals 或者您可以将所有列表保存在另一个列表中,然后使用您的原始想法: all_lists = [] for i in range(5): l = list(range(5)) all_lists.append(l) tot ...
-
您可以使用列表理解: tarfiles = [fname for fname in dirlist if fname.endswith(('.tgz','.tar'))] 要打印文件名,请使用 print "\n".join(tarfiles) 要么 for fname in tarfiles: print fname You can use a list comprehension: tarfiles = [fname for fname in dirlist if fname.endswi ...
-
您可以分配给切片: a[i:j] = map(f, a[i:j]) You can assign to the slice: a[i:j] = map(f, a[i:j])
-
首先,你不能重新分配一个循环变量 - 你可以,但是这不会改变你正在迭代的列表。 因此,设置foo = 0不会改变列表,而只会改变局部变量foo (在每次迭代开始时恰好包含迭代的值)。 接下来,像0和1这样的小数字在内部保存在一个小整数对象池中(这是一个CPython实现细节,并不一定是这种情况!)这就是为什么在您分配后foo的ID相同0到它。 该ID基本上是池中该整数对象0的ID。 如果您想在迭代时更改列表,您将不得不通过索引访问元素。 所以,如果你想保持输出相同,但最后有[0, 0, 0] ,你必须迭代索 ...
-
这个问题的确与CreateJS和更新到最新版本有关。 如前所述,通过使用initialize-method扩展类,之后改为使用SuperClass_constructor,如此处所述。 由于旧代码,按钮未正确创建并导致.on()和.addEventListener()方法出现问题。 循环一直工作! The problem was indeed with CreateJS and updating to the latest version. Previously classes were extended ...
-
行curRad = 'rad' + str(col)完全没有任何结果,因为变量在下一行被重新分配。 代码不会给你任何持久的单独单选按钮 - 但你通常不需要一个:确定选择哪一个,或通过编程选择一个,通过它们共享的变量( radVar )完成。 如果你真的想保留对每个按钮的引用,你可以把: allRads = [] 在循环上方,并且: allRads.append(curRad) 在循环内。 The line curRad = 'rad' + str(col) accomplishes absolutely ...
-
这个操作: [0] * 4 创建一个包含四个零的列表。 这很好,每个都是在python中按值复制的,因为小于255的数字被有效地视为“基元”。 然而, list_of_list = [[0, 0, 0, 0]]* 4 通过引用复制列表。 发生在其中一个列表中的任何内容都发生在所有这些列表中。 This operation: [0] * 4 Creates a list of four zeros. This is fine, each is copied by value in python sinc ...