我的Radar ImageView大部分时间都是在Axis中旋转
但有时当页面重新加载或在我的应用程序的启动时,ImageView在其容器的角落处旋转。
http://i.imgur.com/rOujCf9.gifv
RotateCenter.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<rotate
android:fromDegrees="0"
android:toDegrees="359"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"
android:repeatCount="infinite"/>
</set>
在OnCreate()
中Animation rotateRadarAnimationLooking = AnimationUtils.loadAnimation(this, R.anim.rotate_center);
lookingHostRadar.startAnimation(rotateRadarAnimationLooking);
radar.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingTop="200dp">
<ImageView
android:id="@+id/looking_host_radar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
<TextView
font="ProximaNovaRegular"
android:id="@+id/looking_for_party_text"
android:textSize="18sp"
android:layout_marginTop="20dp"
android:layout_below="@+id/looking_host_radar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/accent_color_light"
android:text="@string/looking_for_party"/>
</RelativeLayout>
radar_layout.xml
<RelativeLayout
android:id="@+id/radar_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/btn_radar_home_settings"
android:layout_width="wrap_content"
android:layout_height="@dimen/shaped_button_height"
android:gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<include layout="@layout/radar"/>
</FrameLayout>
</RelativeLayout>
答案 0 :(得分:0)
我通过将100 dp的大小设置为我的雷达来修复它。
我也可以这样做
lookingHostRadar.getViewTreeObserver().addOnGlobaLayoutListener() {
@Override
public void onGlobalLayout() {
lookingHostRadar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
lookingHostRadar.startAnimation(rotateRadarAnimationLooking);
}
}