Question

I'm having the following screen:

And I'm trying to rotate a text and then set the text on this button.

For that I have the following layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>
<SurfaceView android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:id="@+id/surface_camera" />


<FrameLayout 
android:layout_width="60dip"
android:layout_height="fill_parent"
>
  <Button           android:layout_width="60dip"
                     android:id="@+id/btnPhoto"
                    android:layout_height="fill_parent"/>

 <TextView 
                    android:layout_width="60dip"
                     android:id="@+id/textview"
                     android:textColor="#000000"
                    android:layout_height="fill_parent"
                  />

</FrameLayout>
 </RelativeLayout>

And then I try to use animations in order to rotate my text :

File:res/anim/myanim:

<?xml version="1.0" encoding="utf-8"?>
<rotate  xmlns:android="http://schemas.android.com/apk/res/android"
       android:fromDegrees="0" 
       android:toDegrees="-90"
       android:pivotX="50%"
       android:pivotY="50%"
       android:duration="0" />

And then I do in onCreate():

te = (TextView) findViewById(R.id.textview);
      te.setText(t);

     RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this, R.anim.myanim);
     ranim.setFillAfter(true);
    te.setAnimation(ranim);

But unfortunately no text appears on my button.Anyone any ideas?

Was it helpful?

Solution

Create a folder named anim and then create xml file and add this below xml

<rotate 
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0" 
android:toDegrees="360" 
android:pivotX="50%"
android:pivotY="50%"
 android:repeatCount="infinite" 
 android:duration="1200" />

then add below line on textview in xml where you defined your textView.

android:interpolator="@anim/linear_interpolator" 

and final apply below code...

Animation logoMoveAnimation = AnimationUtils.loadAnimation(Animation2DActivity.this,
                    R.anim.linear_interpolator);
            mobjectImageButton.startAnimation(logoMoveAnimation);

enjoy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top