2

I want to put my EditText in a particular position in the screen in my Android application but I can't see any method to put it in the right pixel or using x and y coordinates to place it in the position in which it have to appear.

My EditText it's this:

<EditText android:id="@+id/txtExample"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:width="250dp"
        android:layout_marginTop="30dp"
        android:layout_below="@+id/lblExample"
        android:layout_centerHorizontal="true" />

There is below this EditText, as you can see, a label but I put this EditText calculating the margin with the label above it so I'm trying to search, without any result, some feature of Android like android:..., if it is possible, to place it in the left-hand corner to make the reference of where you want to place your element.

Any help would be appreciated.

Thanks in advance!

Francisco Romero
  • 12,787
  • 22
  • 92
  • 167
  • This is 2015, not 1990. Designing GUIs based upon absolute pixel coordinates has been considered to be poor form for quite some time, in most modern GUI frameworks for most operating systems (and the Web to boot). – CommonsWare May 28 '15 at 00:22

2 Answers2

3

Using specific pixels is obsolete, as we use the concept of 'dp' as no of pixels change per device. If you want to place at some specific position use 'gravity' and 'margin' to position it. It's the easiest and best way to do it quickly.

xblack
  • 581
  • 2
  • 8
  • Thanks for answer! I was using a RelativeLayout with margins but all the items put behind the others and they overlap. It's why I ask for a method to put them static on the screen. – Francisco Romero May 28 '15 at 17:37
1

Set absolute position possible inside FrameLayout.

With RelativeLayout it's cumbersome, but have a look:

set the absolute position of a view

Community
  • 1
  • 1
Andrew
  • 36,676
  • 11
  • 141
  • 113
  • Thanks for answer but I was looking for a feature in Android to put in the xml (like `android:...` to make something like this, not by code. Anyway, thank you. – Francisco Romero May 28 '15 at 18:52