0

This is my problem: I have a (horizontally) very large View and, of course, I have a scroll to move it side by side. I want to put a TextView in middle, but I want it so, that when I scroll horizontally and the View moves this TextView stays in the center of the screen.

If I use android:gravity="center" or something like this, as the view is very large, I will NOT see the TextView in the center unless I am in the center of the view (Not in the beginning, and not in the end) but I need that the TextView is in the center during the whole scrolling.

SztupY
  • 10,291
  • 8
  • 64
  • 87
Milena
  • 27
  • 4
  • Although you said this is a large lib, you should create a smaller variant of your problem, so people could check it easier (which would mean you might get an answer more quicker) – SztupY Mar 05 '13 at 16:38

2 Answers2

2

I think that you can achieve that by positioning the element in the middle by setting its x-origin (with left-padding or left-margin?) to (scrollview.width/2 - textview.width/2), then add the scrollview.offset.x whenever the scrollview scrolls (add a listener to get this) so it maintains still at the relative center.

However the simplest thing may be to place a FrameLayout which contains the ScrollView and above it the TextView, which you could then center with the gravity property.

htafoya
  • 18,261
  • 11
  • 80
  • 104
0

Presumably your content is all inside a ScrollView. You will need your TextView to be outside of this scroll view: you can then use the technique described in "Android overlay a view ontop of everything?" to place the TextView where you want it.

Community
  • 1
  • 1
Jules
  • 14,841
  • 9
  • 83
  • 130