[英]How to set the position of textView using X and y coordinates
I tried using the drag and drop function but when the program runs, the textView objects go to 0,0. 我尝试使用拖放功能,但是当程序运行时,textView对象将变为0,0。 How do I solve this issue?
我该如何解决这个问题?
If I'm understanding your problem correctly, you need to use constraints. 如果我正确地理解了您的问题,则需要使用约束。 For example, say you have this
editText
object: 例如,假设您具有以下
editText
对象:
You could set it so that it is a specified number of dp
, or Density Independent Pixels, from another object eg the left white circle (drag and drop to create constraints) of the editText
box could be dragged to the edge on the left which would constrain it to that edge. 您可以对其进行设置,以使其为另一个对象的指定数量的
dp
或“密度独立像素”,例如,可以将editText
框的左侧白色圆圈(拖放以创建约束)拖至左侧的边缘,将其约束到该边缘。 You then tell it to be so many dp
away, say 20dp
from the left so it appears like so: 然后,您告诉它有很多
dp
,例如从左侧说20dp
,这样看起来就这样:
You can change the value of the constraint's dp
in the right-hand Properties
column which would show like this: 您可以在右侧的“
Properties
列中更改约束的dp
值,如下所示:
You would then change the 8 to 20. 然后将8更改为20。
In addition, you can set these constraints programmatically in the XML code by adding the statement such as: 另外,您可以通过添加以下语句在XML代码中以编程方式设置这些约束:
android:layout_marginLeft="20dp"
within the object's code making it look like this: 在对象的代码中使其看起来像这样:
As I'm sure you can tell, the examples I've given have constrained the object to the left bound/edge of the screen. 如您所知,我所给出的示例已将对象限制在屏幕的左边界/边缘。 You can also set constraints based on other objects surrounding the one you wish to constrain as well as parent objects.
您还可以基于要约束的对象以及父对象周围的其他对象设置约束。 You then add constraints to the top, right and down positions as needed.
然后,根据需要将约束添加到顶部,右侧和向下位置。
Hope I've explained it well enough and that it helps you. 希望我对它的解释足够好,对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.