我想使用一个动画,其中alpha值随着椭圆比例的增加而减小。
TypeError Traceback (most recent call last)
<ipython-input-6-4ccb4b105a41> in <module>()
5 images = images.reshape(-1,28*28)
6
----> 7 outputs = model(images)
8 loss = loss_function(outputs, labels)
9 loss_items.append(loss.item())
~/.local/lib/python3.6/site-packages/torch/nn/modules/module.py in
__call__(self, *input, **kwargs)
475 result = self._slow_forward(*input, **kwargs)
476 else:
--> 477 result = self.forward(*input, **kwargs)
478 for hook in self._forward_hooks.values():
479 hook_result = hook(self, input, result)
~/Desktop/Archive/Computing/Projects/Python/ai/neural_network.py in
forward(self, x)
28 for i in range(len(self.layer_shapes)-1):
29 lin = self.linear_functions[i](y)
---> 30 y = self.activation_functions[i](lin)
31 return y
32
TypeError: __init__() takes 1 positional argument but 2 were given
上图显示了动画步骤,而不是实际步骤。 (也就是说,上图显示了五个相同的波纹动画,它们是延迟运行的。)
我目前正在通过为每个动画创建一个视图并开始每个视图来实现这一点。
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale="0"
android:fromYScale="0"
android:toXScale="2"
android:toYScale="2"
android:repeatCount="infinite"
android:repeatMode="restart"
/>
<alpha android:fromAlpha="1"
android:toAlpha="0"
android:repeatCount="infinite"
android:repeatMode="restart"/>
</set>
code.kt
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:elevation="5dp">
<ImageView
android:id="@+id/imageView2"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical|end"
android:background="@drawable/button"/>
<ImageView
android:id="@+id/imageView3"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical|end"
android:background="@drawable/button"/>
<ImageView
android:id="@+id/imageView4"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical|end"
android:background="@drawable/button"/>
<ImageView
android:id="@+id/imageView5"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical|end"
android:background="@drawable/button"/>
<ImageView
android:id="@+id/imageView6"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical|end"
android:background="@drawable/button"/>
<Button
android:id="@+id/button"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical|end"
android:background="@drawable/button"
android:textColor="#000"/>
</FrameLayout>
结果,这种方法满足了我的需求,但是我觉得有太多无用的视图无法代表一个流程。
有没有更有效的方法?