Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change position of image view

i can't change the position of the login button.Because when i try, it can't be moved from the original position. I' ve set the android:layout_gravity and android:gravity but i want it in a specific position.

how i can set the coordinates (x,y) of the image?

this is the 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" />
like image 363
OiRc Avatar asked Aug 10 '14 08:08

OiRc


2 Answers

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

Beware that every screen has different number of pixels, you might have different result on different devices.

Sample:

ImageView s = (ImageView) findViewById(R.id.your_id);
s.setY(number);
s.setX(number);
like image 178
Rod_Algonquin Avatar answered Oct 12 '22 17:10

Rod_Algonquin


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);
like image 20
Vijay Barbhaya Avatar answered Oct 12 '22 17:10

Vijay Barbhaya