android - 从xml旋转android drawable而不切割
问题描述
我必须在回收器视图的一个项目的 xml 中执行此操作(我正在使用数据绑定和查看器模式)。根据绑定到视图的变量的值,我需要旋转一个可绘制对象并将其设置src
为ImageView
.
我在网上检查了很多选项,但没有找到任何选项,旋转45 degrees
了形状的某些部分的原始 xml 可绘制切割,这是一个弯曲的矩形。这会导致形状不符合要求。
我需要有关如何从 xml 或适配器内部完成此操作的建议,而无需将其重写为使用getView
.
解决方案
您好@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);
推荐阅读
- amazon-web-services - 如何下载公共 AWS S3 存储桶?
- angular - ngIf 语句在 Ionic 4 中多次执行
- c# - 如果先提取任务,则异步任务死锁
- python - zipline:target_order 未在 handle_data 中执行
- python - 转换为熊猫数据框时如何删除csv中的自动索引
- ios - SWIFTUI:- 有没有办法在滚动滚动视图时关闭弹跳?
- python - Python/MySQL - 从数据库中导出 CSV 文件
- ruby-on-rails - 将 pluck 与本地化 I18n / globalize 一起使用时出现重复值
- algorithm - 如何为给定的时间复杂度构建算法?
- firebase - 使用 Provider 在 Flutter 中进行 Firebase 电话身份验证