【发布时间】:2018-09-26 06:45:41
【问题描述】:
我正在 ImageView 上运行旋转动画。问题是位图已被剪切以完全适合 ImageView。所以当它旋转时,它并没有完全覆盖 ImageView 以及屏幕。
这就是我想要的
这就是发生的事情
xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.LevelCompletedFragment">
<RelativeLayout
android:id="@+id/vgBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#3f5d68"
android:alpha="1">
</RelativeLayout>
<ImageView
android:id="@+id/ivStarburst"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/star" />
</FrameLayout>
运行动画
Animation shake = AnimationUtils.loadAnimation(mContext, R.anim.clockwise_rotation);
**ivStarburst.startAnimation(shake);
编辑: 遵循@deadfish 的解决方案后,只有当我在 MainActivity 的 onCreate() 中打开片段时,动画才能正确运行。如果我在 onClick() 方法中触发片段,它就不起作用。
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
MainFragment frgm = new MainFragment ();
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, frgm).commit();
}
【问题讨论】:
-
尝试在 ImageView 中使用
android:background="@drawable/star"而不是src并删除android:scaleType="centerCrop" -
我不希望位图失真。它使该部分看起来很奇怪
-
然后设置
scaleType:fitXY -
我尝试了所有不同的比例类型,它不起作用,伙计
-
让@drawable/star里面包含的rotate drawable,并通过ValueAnimator改变它的rotation属性
标签: android android-layout android-animation android-xml