Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Move an image inside an ImageView

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day All

I am using Android Studio 3.6.3

The scenario I need to set up is as follows;

I need a picture inside an ImageView (or something similar). The picture starts in the centre of the ImageView. I need one button which will rotate the ImageView (and thus also rotate the picture inside the ImageView).
A second button which will move the picture inside the ImageView (but NOT the ImageView) along the X line.

The code for the ImageView is

<ImageView
 android:id="@+id/mymap"
 android:layout_width="500dp"
 android:layout_height="300dp"
 android:layout_gravity="center"
 android:background="@drawable/mapsmall"/>

The picture is the item @drawable/mapsmall

I define the ImageView in Java as

imageView = (ImageView) findViewById(R.id.mymap);

The code for the rotate animation is

ObjectAnimator rotateMap = ObjectAnimator.ofFloat(imageView,
               "rotation", 0f, 180f)
               .setDuration(1000);

The code for the moveX is

ObjectAnimator moveX = ObjectAnimator.ofFloat(imageView,
               "translationX", 200f, 500f)
               .setDuration(1000);

Now the rotation works fine and rotates the ImageView.
The MoveX works well and moves the ImageView.

Since both animations target

imageView = (ImageView) findViewById(R.id.mymap);

This may be no surprise.

In the MoveX animation how do I TARGET ONLY the picture which is inside the ImageView and not the whole ImageView? My Animation requires me to move the image inside the imageView (if this is possible)

I am new to AS (that may be obvious from my code).

I have previously coded this animation successfully in both ActionScript3 as wel as in Javascript. I know that Java is a much more powerful code than either. it MUST be possible to do this ?

Any help will be greatly appreciated.

Thanks

Paul
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic