Android 更改图像视图的位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25226730/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
change position of image view
提问by theitroadc
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.
我无法更改登录按钮的位置。因为当我尝试时,它无法从原始位置移动。我已经设置了android:layout_gravity
和android:gravity
但我希望它在一个特定的位置。
how i can set the coordinates (x,y) of the image?
我如何设置图像的坐标(x,y)?
this is the login_fragment.xml
这是 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" />
回答by Rod_Algonquin
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.
您不能在 xml 本身内执行此操作,您需要ImageView
在您的活动中创建该实例的实例并调用其setX()
或setY()
方法来设置坐标。
Bewarethat 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);
回答by Vijay Barbhaya
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);