gpt4 book ai didi

安卓。在 fragment 中旋转动画

转载 作者:搜寻专家 更新时间:2023-11-01 08:36:44 25 4
gpt4 key购买 nike

我有一个扩展 Fragment 的类,我想在调用 onCreateView() 时旋转 ImageView。

这是我的代码:

rotator.xml - 设置动画

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate xmlns:android="”http://schemas.android.com/apk/res/android”"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="1"
android:duration="1000"/>
</set>

这里我使用我的动画:

public class SearchFragment extends Fragment {

Context context;

private ImageView backButtonImage;
private Animation rotation;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

context = container.getContext();


View root = inflater.inflate(R.layout.search, container, false);

backButtonImage = (ImageView) root.findViewById(R.id.backButton);

rotation = AnimationUtils.loadAnimation(context, R.anim.rotator);
backButtonImage.startAnimation(rotation);

return root;
}

但是,当我运行我的应用程序时,图像不会旋转。我做错了什么?

最佳答案

你的 rotator.xml 有问题:

<rotate xmlns:android="”http://schemas.android.com/apk/res/android”"

你有一组在 xml 中无效的额外引号,它应该是这样的:

<rotate xmlns:android="http://schemas.android.com/apk/res/android"

但是你甚至不需要指定 xmlns:android 属性,因为你已经在你的根元素上做了它,所以整个文件可以是这样的:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="1"
android:duration="1000"/>
</set>

关于安卓。在 fragment 中旋转动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36206303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com