繁体   English   中英

在HoneyComb版本以下的android中,应旋转ImageVIew的旋转位置

[英]Rotating an ImageVIew should be CLICKED in its rotated position in android below HoneyComb versions

我正在尝试旋转ImageView及其原始位置(旋转图像以及视图)。 这样,旋转后,当我单击旋转图像的当前位置时,应该只能在旋转位置单击它。

对于此解决方案,我正在尝试以下代码。 但是它旋转得很好。 旋转结束后,我需要将ImageView和Image放置在旋转的位置,以使其只能在那儿单击。 但这并没有成功。 我无法旋转图像位置轴点以正确放置。 可以请任何人提出解决此问题的方法。

fyi-它应该适用于姜饼版本android-9

 aniView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("", "Clicked on IMAGE VIEW - 1");
            }
        });

        RotateAnimation rotate5 = new RotateAnimation(0, 150,
                Animation.INFINITE, 100, Animation.INFINITE, 250);
        //rotate5.setFillAfter(true);
        rotate5.setDuration(2000);
        rotate5.setInterpolator(new LinearInterpolator());
        aniView1.setAnimation(rotate5);

        rotate5.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {

                int newTop = (int) (aniView1.getTop() + aniView1.getWidth());

                aniView1.layout(aniView1.getLeft()-200, newTop,
                        aniView1.getRight(),
                        aniView1.getBottom() + aniView1.getMeasuredWidth());

                // aniView1.setLayoutParams(new
                // RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT));

            }
        });

尝试这个。 它对我有用。 动画状态将由此保留

编辑:

好的,我可以在我的应用中使用以下代码来做到这一点:

Animation rotateAnim = new RotateAnimation(0, 360, Animation.ABSOLUTE, Animation.ABSOLUTE, Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF);
        rotateAnim.setDuration(5000);
        rotateAnim.setRepeatCount(1);
        rotateAnim.setInterpolator(new AccelerateInterpolator());
        rotateAnim.setRepeatMode(Animation.REVERSE);
        rotateAnim.setFillEnabled(true);
        rotateAnim.setFillAfter(true);

将此文件放在android res-> anim-> loading_rotation.xml下

<?xml version="1.0" encoding="UTF-8"?>
<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:duration="1200" 
    android:interpolator="@android:anim/linear_interpolator"/>

和你的活动

view.startAnimation(AnimationUtils.loadAnimation(context,
                R.anim.loading_rotation));

而你想停止的地方只是打电话

view.clearAnimation();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM