I have a layout resource file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFFFF"
android:layout_gravity="top|left"
android:visibility="gone"/>
</FrameLayout>
At a certain point in time, this layout will be shown in my work. At this point, I set the visibility thumbnail ImageViewto View.VISIBLE, and then I want to revive it so that it occupies 30% of the width / height of the screen, located marginPixelsfrom the top left corner (on my test device it marginPixelsis 48). This will open the base View, with the exception of the part accepted thumbnail.
To this end, I have the following Java:
thumbnail.setVisibility(View.VISIBLE);
thumbnail
.animate()
.scaleX(0.3f)
.scaleY(0.3f)
.x(marginPixels)
.y(marginPixels)
.setDuration(animDuration);
As a result, animation occurs, but thumbnailis in the center FrameLayout.
I tried:
Both have and don't have android:layout_gravity="top|left"on ImageViewin the layout xml
translationX(marginPixels)/ translationY(marginPixels)instead of x(marginPixels)/y(marginPixels)
translationXBy(marginPixels)/ translationYBy(marginPixels)instead of x(marginPixels)/y(marginPixels)
, , . thumbnail . x() y(), , , - . scaleX() scaleY() ( x() y(), ), thumbnail , - , . setX() setY() thumbnail x() y(), thumbnail , , .
, , , . , x()/y() ViewPropertyAnimator, , .
UPDATE. (, , ), , ):
int x=(int)(-0.35f*(float)bmp.getWidth())+marginPixels;
int y=(int)(-0.35f*(float)bmp.getHeight())+marginPixels;
thumbnail.setVisibility(View.VISIBLE);
thumbnail.setImageBitmap(bmp);
thumbnail
.animate()
.x(x)
.y(y)
.scaleX(0.3f)
.scaleY(0.3f)
.setDuration(animDuration);
, , . IOW, x y ?