Mohammad Ersan
Mohammad Ersan

Reputation: 12444

Animate Translate View to edge of screen

I was trying to Animate View from its location to the edge of the screen , and 100%p was getting the view out of the screen,

required animation

the image describe the required animation, for anyone asking for the code:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fillAfter="true" >

    <translate
        android:fromXDelta="0%"
        android:toXDelta="100%" />

</set>

any help would be appreciated

Upvotes: 2

Views: 2172

Answers (1)

ben75
ben75

Reputation: 28706

From android doc:

android:toXDelta

Float or percentage. Ending X offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element width (such as "5%"), or in percentage relative to the parent width (such as "5%p").

Assuming your button width is 20% of it's parent width, you must specify your toXDelta as

50%p-(20%p/2) = 40%p

The problem with this solution is that you probably don't know the button width in terms of "% of it's parent width" (not sure since you didn't post the xml). So I would suggest to define your animation programmatically.

Upvotes: 6

Related Questions