首页 > 解决方案 > 从xml旋转android drawable而不切割

问题描述

我必须在回收器视图的一个项目的 xml 中执行此操作(我正在使用数据绑定和查看器模式)。根据绑定到视图的变量的值,我需要旋转一个可绘制对象并将其设置srcImageView.

我在网上检查了很多选项,但没有找到任何选项,旋转45 degrees了形状的某些部分的原始 xml 可绘制切割,这是一个弯曲的矩形。这会导致形状不符合要求。

我需要有关如何从 xml 或适配器内部完成此操作的建议,而无需将其重写为使用getView.

标签: androidxmllayoutgraphics

解决方案


您好@staa99 尝试以下代码可能会对您有所帮助。

ImageView imageView = findViewById(R.id.imageView);
RotateAnimation anim = new RotateAnimation(0, 45,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);

anim.setInterpolator(new LinearInterpolator());
anim.setDuration(1000);
anim.setFillEnabled(true);
anim.setFillAfter(true);
imageView.startAnimation(anim);

推荐阅读