1

I'm trying to do a RotationAnimation (an ImageView) on an Android Wear.

I tested a sample on an Android Tablet and it works perfectly but the ImageView disappears on the Android Wear.

How can I do it on android Wear ?

This is the layout :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/rotatecenter"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Rotate around center"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center"
        android:weightSum="1">

        <ImageView
            android:id="@+id/floatingimage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />

    </LinearLayout>

</LinearLayout>

This is rotationanimation 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="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="2000"
        android:startOffset="0"/>
</set>

Finally this is the Activity code:

Animation rotate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my2);

        Button buttonRotateCenter = (Button)findViewById(R.id.rotatecenter);

        final ImageView floatingImage = (ImageView)findViewById(R.id.floatingimage);

        final Animation animationRotateCenter = AnimationUtils.loadAnimation(this, R.anim.rotate_center);
        buttonRotateCenter.setOnClickListener(new Button.OnClickListener(){

            @Override
            public void onClick(View arg0) {
                floatingImage.startAnimation(animationRotateCenter);
            }});


    }

Thanks.

Samy Sup
  • 298
  • 2
  • 16
  • Show us the XML for both animation and layout as well as your code. – Pedro Oliveira Oct 01 '14 at 15:12
  • I just added the code :). This is just an example but I would like to put my ImageView in a RelativeLayout ! – Samy Sup Oct 02 '14 at 08:58
  • May be too late for @SamySup but for the benefit of others, the rotation code works correctly in my testing and I can see no indication in the API documentation that AnimationUtils is not fully supported by Android Wear. It may have been an issue with your device or emulator. – BrentM Feb 06 '15 at 23:44

0 Answers0