简体   繁体   English

如何使用X和y坐标设置textView的位置

[英]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对象:

不受约束的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 ,这样看起来就这样:

editText从左边限制为20px

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.

相关问题 如何在java图形中使用x和y坐标定位形状? - How to position a shape using x and y coordinates in java graphics? 如何在框架中设置按钮的X,Y位置? - How to set the X,Y position of button in frame? 绝对布局中的ImageView,如何设置ImageView的x,y坐标? - ImageView within an AbsoluteLayout, How to set x, y coordinates of the ImageView? 如何将多个对象的x,y,z坐标转换为显示这些对象位置的Android应用程序? - How could I turn coordinates x,y,z coordinates of several objects into an Android app that displays the position of these objects? 使用x和y坐标计算区域,如何在x和y中打破数字组? - Computing area with x and y coordinates, How do I break set of numbers in x and y? 如何使用x,y坐标列表绘制曲线(峰值) - How to Drawing a curve line(peaks) using list of x,y coordinates 如何使用x和y坐标获取特定元素的标题? - How to get the title of an particular element using x and y coordinates? 如何使用selenium获取android native app的x,y坐标 - How to get x,y coordinates of android native app using selenium Android SDK设置ImageView的XY坐标 - android sdk set imageview x y coordinates 如何在不更改Y坐标的情况下在X坐标中设置鼠标位置 - How to set mouse position in X coordinate without changing the Y coordinate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM