gpt4 book ai didi

android - 更改 ImageView 的位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:58:11 25 4
gpt4 key购买 nike

我无法更改登录按钮的位置。因为当我尝试时,它无法从原始位置移动。我设置了 android:layout_gravityandroid:gravity 但我希望它处于特定位置。

如何设置图像的坐标 (x,y)?

这是 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" />

最佳答案

您不能在 xml 本身中执行此操作,您需要在 Activity 中创建该 ImageView 的实例并调用其 setX()setY( ) 方法来设置坐标。

注意每个屏幕都有不同的像素数,您在不同的设备上可能会有不同的结果。

示例:

ImageView s = (ImageView) findViewById(R.id.your_id);
s.setY(number);
s.setX(number);

关于android - 更改 ImageView 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25226730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com