3

I have a TextView. How can I position it by using x and y coordinates?

TextView leftArrow = new TextView(this);
    leftArrow.setTypeface(tf);
    leftArrow.setText("<");
    leftArrow.setTextSize(30);
    ll.addView(leftArrow);
0xCursor
  • 2,242
  • 4
  • 15
  • 33
JeffLemon
  • 281
  • 3
  • 6
  • 14

2 Answers2

5

you can use view.setX() and view.setY() ,see the following link

http://developer.android.com/reference/android/view/View.html#setX(float)

Yashwanth Kumar
  • 28,931
  • 15
  • 65
  • 69
  • 2
    You could also use view.setLeft(int left) and view.setTop(int top), setPadding(int left, int top, int right, int bottom), or view.setLayoutParams() (with margin settings for the layout parameters). – Ben Jakuben Sep 08 '11 at 21:49
0

If you really, really want x,y positioning, use the deprecated AbsoluteLayout -- but read Alternative to AbsoluteLayout in Android? before (it's no good for different screen sizes).

You'll likely fare much better with RelativeLayout depending on your problem.

Community
  • 1
  • 1
Philipp Reichart
  • 20,771
  • 6
  • 58
  • 65