Change image position

I cannot change the position of the login button. Because when I try, it cannot be moved from the starting position. I set android:layout_gravity and android:gravity , but I want it in a specific position.

How can I set the coordinates (x, y) of an image?

this is login_fragment.xml

 LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:gravity="center" android:orientation="vertical" <ImageView android:id="@+id/login" android:layout_width="400px" android:layout_height="100px" android:src="@drawable/login_button" /> 
+7
android imageview
source share
2 answers

You cannot do this inside xml itself, you need to create an instance of this ImageView in your activity and call its setX() or setY() method to set the coordinates.

Beware that each screen has a different number of pixels, you can have different results on different devices.

Example:

 ImageView s = (ImageView) findViewById(R.id.your_id); s.setY(number); s.setX(number); 
+10
source share
 TranslateAnimation animation = new TranslateAnimation(0.0f, 50.0f, 0.0f, 0.0f); animation.setDuration(700); animation.setRepeatCount(5); animation.setRepeatMode(2); animation.setFillAfter(true); image.startAnimation(animation); 
+3
source share

All Articles