0

Upon starting an activity, I want the screen to shift to x=5000, y=0. I used the following to try and achieve that:

//to aid in moving the focus to the main view.

TextView textView = new TextView(this);
textView.setFocusable(true);
textView.setVisibility(View.INVISIBLE);
params.setMargins(5000,0,10,10);
rl.addView(textView,params);
textView.requestFocus();

However it does not work, the focus is not moving to that location. Any help appreciated!

Bentaye
  • 9,403
  • 5
  • 32
  • 45
Adam J
  • 183
  • 2
  • 14
  • What you want to acheive? Change margins of TextView programatically? First, put it in xml layout in RelativeLayout, then use this answer: https://stackoverflow.com/questions/3416087/how-to-set-margin-of-imageview-using-code-not-xml – thorin86 Jun 17 '17 at 14:57
  • No I want to move to x=5000,y=0 upon starting an activity, thanks – Adam J Jun 17 '17 at 15:17

1 Answers1

0

From API 11 you can do the following

textView.setTranslationX(5000);

or if you want to change Y use:

textView.setTranslationY(your value expecting an int));
Gil Goldzweig
  • 1,809
  • 1
  • 13
  • 26
  • Hello this is not shifting the focus all the way to that position upon starting an activity, thanks for the reply. – Adam J Jun 18 '17 at 07:19
  • What do you mean not shifting the focus all the way you mean it slide out side of the screen? – Gil Goldzweig Jun 18 '17 at 07:22
  • By sliding it off the screen to x=5000 I want the screen to move there too, thats why I thought requestfocus() would work on the textview once i moved it to that position – Adam J Jun 19 '17 at 08:53
  • that would be possible if your rootview is a scrollview – Gil Goldzweig Jun 19 '17 at 10:00