Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to scale animate android text view to the right

I am trying to have text come in from the left hand side of the screen, and when it gets to its position I want the text to scale towards the right side of the TextView. This is the animation file.

<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is where the view moves onto the screen -->
<translate
android:fromXDelta="-200%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="1000"
android:zAdjustment="top" ></translate>
<!-- this is where I am scaling the text it currently aligns on the left side of the textview -->
<scale
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale=".2"
android:startOffset="500"
android:toYScale="1.0"
android:duration="1000"></scale>
<!-- I am then trying to make the text bounce over the left side of the textview -->
<scale
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="7.0"
android:startOffset="1500"
android:toYScale="1.0"
android:duration="200"></scale>
<!-- I am then resetting the text to its original size -->
<scale
android:fromXScale="1.4"
android:fromYScale="1.0"
android:toXScale="1.0"
android:toYScale="1.0"
android:startOffset="1700"
android:duration="50"></scale>
 </set>

I am also doing this for when text comes in from the right side and that works fine. This is where the textViews are in the layout

    <TextView android:textColor="@android:color/black" android:textSize="50dip" android:layout_marginTop="40dip" android:layout_width="wrap_content" android:gravity="right" android:id="@+id/btnN" android:text="@string/play" android:layout_height="wrap_content" android:layout_marginLeft="50dip"></TextView>

    <TextView android:textColor="@android:color/black" android:layout_marginBottom="40dip" android:textSize="50dip" android:layout_width="wrap_content" android:gravity="right" android:id="@+id/btnO" android:text="@string/option" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginLeft="50dip"></TextView>

    <TextView android:id="@+id/btnI" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/info" android:textColor="@android:color/black" android:layout_marginRight="50dip" android:layout_marginTop="40dip" android:textSize="50dip" android:layout_alignParentRight="true"></TextView>

    <TextView android:id="@+id/btnE" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@android:color/black" android:text="@string/exit" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="40dip" android:layout_marginRight="50dip" android:textSize="50dip"></TextView>
</RelativeLayout>
btnN and btnO are the ones I need to do this animation for
like image 236
Bryce Meyer Avatar asked Nov 29 '11 21:11

Bryce Meyer


People also ask

Which method is used to change the text size of the text view?

Use sp for text size… because but it is scaled by the user's font size preference. Use dp for everything else.

How do you animate a view?

Create ImageView in the activity_main. xml along with buttons that will add animation to the view. Navigate to the app > res > layout > activity_main. xml.

What is Alpha Animation in Android?

An animation that controls the alpha level of an object. Useful for fading things in and out.


1 Answers

set android:pivotX="100%" to scale in your animation XML file.

And in java file:

Animation anim = AnimationUtils.loadAnimation(context, R.anim.yourAnimation);
yourTextView.startAnimation(anim);
like image 193
Abolhassan Pirayeh Avatar answered Oct 23 '22 01:10

Abolhassan Pirayeh