Mina Eun-hye
Mina Eun-hye

Reputation: 31

Android: animating imageview

I am working with my splash screen. I want to have a animating imageview (from left to right). My code really works but the scrolling starts with black color..

What I want to is start the animating from the entire image.

For clear understanding here is my screenshot:

My problem:

enter image description here

My target output

enter image description here

public class splash extends Activity {

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

        ImageView img_animation = (ImageView) findViewById(R.id.img_animation);
        TranslateAnimation animation = new TranslateAnimation(0, 720, 239, 0);
        animation.setDuration(10000);
        animation.setFillEnabled(true);
        img_animation.startAnimation(animation);
    }
}

Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".Animation" >

    <ImageView
        android:id="@+id/img_animation"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/splash_1"
        android:scaleType="centerCrop" />

</RelativeLayout>

Upvotes: 2

Views: 118

Answers (2)

Emre Tekin
Emre Tekin

Reputation: 11

Use FrameLayout for positioning imageview to start of view and get imageview width = y and screen width = x then animate y-x.

You can use ObjectAnimator. This nineoldandroid library and its pretty same with default android Object animator.

  AnimatorSet set = new AnimatorSet();

     long scaleXAmount = y - x; (I mentioned it on above)
     set.playTogether(
           ObjectAnimator.ofFloat(view, "translationX", 0, scaleXAmount )
       );
  set.setDuration(800).start();

Upvotes: 1

sadegh saati
sadegh saati

Reputation: 1170

I think if set width of both RelativeLayout and ImaveView to wrap_content and set adjustViewBound of imaveview "true" it would work

Upvotes: 0

Related Questions