0

I will start off with an illustration of what I would like to achieve. I have an image that I would like to slide across the screen.

enter image description here

The problem is that the image is automatically adjusted to fit the aspect ratio of the screen.

I start with an ImageView

<ImageView
     android:id="@+id/slidingImage"
     android:src="@drawable/gazelleRunning"
     android:layout_width="match_parent"
     android:layout_height="match_parent"/>

And then I set the background of the ImageView

ImageView gazelleRunning = (ImageView) findViewById(R.id.gazelleRunning);
Bitmap bitmap = BitmapFactory.decodeFile(URI_Object); 
Drawable drawable = new BitmapDrawable(getResources(), bitmap);

gazelleRunning.setBackground(drawable); 

The animation is no problem. Like I said, the problem is that the image is automatically adjusted to fit the aspect ratio of the screen.

the_prole
  • 8,275
  • 16
  • 78
  • 163
  • These links should give you some idea- http://stackoverflow.com/questions/18073588/androidhow-can-i-show-a-part-of-image – Ramesh Prasad Oct 16 '15 at 12:10
  • http://stackoverflow.com/questions/3466297/how-to-display-a-part-of-an-image – Ramesh Prasad Oct 16 '15 at 12:10
  • @RameshPrasad Thanks, but I'm thinking a animated scroll view might actually be able to fit the entire image into the view and scroll it basically. – the_prole Oct 16 '15 at 21:42

1 Answers1

0

The problem with the aspect ratio was that I hand't set the width and height of the image to wrap_content

In so far as the sliding in concerned, I solved that problem by implementing a transformation.

Animation animationSlideInLeft = AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_in_from_right);
gazelleRunning.startAnimation(animationSlideInLeft);

The animation file

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    <translate
        android:duration="5000"
        android:fromXDelta="200%"
        android:toXDelta="0%"
        />
</set>
the_prole
  • 8,275
  • 16
  • 78
  • 163