How to control the LinearLayout In the ScrollView In Android Eclipse? - android

Hi there I am in the middle of developing my app and am just curious to find out whether or not this is possible.
Ok so I have loads of text in my Layout and I want to pragmatically control where the linear layout in the scroll view has been pressed.
For example I want to program my app to go in the middle of my text how would I do that?

What about using the "scrollTo" function. Programatically you will be able to specify the x and y to scroll to.
http://developer.android.com/reference/android/widget/ScrollView.html#scrollTo(int, int)
Here is an example of how to use the scrollBy and scrollTo methods. Essentially you give it an offset in pixels for the amount you want to scroll. You can use getScrollX and getScrollY to get positions, though it sounds in your case you might want to use "scrollBy" to scroll an offset based on the top of the scroll view and where the user pressed.
http://android-er.blogspot.com/2011/09/scroll-view-scrollby-and-scrollto.html

Related

How can I scroll item to middle of screen in scrollView when I press them

My project need to insert lots of data,I use scrollview to put them in one page.
Now I want it can scroll the item I press(primary Edittext) to the middle of screen.
I tried to use onFocusChangeListener()+scrollTo() with edittexts,but doesn't work very well.
Is there any better way to do it?
Have an onTouchListener for the scrollview.
When the user touches the screen, grab the x and y coordinates and then simply scroll to that point. So scrollview.scrollTo(x,y).
See here for more info

How to enable zoom in ScrollView?

How to enable zoom in Scrollview?
Here is an application that uses this function very well and works in API9 and more:
The zoomcontrol hide after 2 seconds without user interaction.
The view you are seeing is a WebView as mentioned by Waza_Be in their comment.
If you want to implement something like this in Android, you can either use a WebView yourself and add text/images etc to this as HTML code. See Building Apps In WebView.
If you absolutely have to use ScrollView you will have to create your own custom implementation.
You could have a RelativeLayout that contains the ScrollView and the two Buttons for zooming in and out. Have the Buttons in their own LinearLayout with orientation="horizontal" and set this to align with the bottom right of the parent RelativeLayout.
That will give you the floating buttons above the ScrollView.
You can then detect a tap on the ScrollView, or when it scrolls using the example given in this StackOverflow article (ScrollView does not support an OnScrollListener as such).
When you detect a scroll/tap, you can then set the Button layout to be visible, and remove visibility after 2 seconds with a Timer or a Thread that sleeps for 2000ms.
To achieve zooming, you would have to increase the of the TextView font size for each (+) click and decrease it for every (-) click. For Bitmaps you could similarly scale the Bitmap to fill the new size.
A lot of work for what you want to achieve. Try to stick to WebView or find another way of representing your application.

Android - keeping a single element contained on screen

I'm experimenting to see if the layout scheme I want to use is possible. I want to have an XML layout that's scrollable. Within that scrollable layout, I want to have a single line going horizontally across the screen (I used just a View with a fixed height and different color). When that horizontal line reaches the top of the screen, and as I scroll down through the layout, I want it to stop and remain at the top of the screen while being able to scroll through everything below it.
I've been messing around in XML trying to get it to work, basically putting a bunch of junk before it and after it.
Any ideas as to how that might work? Would I have to do something fancy with the java code to fix the red line at the top when the scroll position reaches a certain point? Your help would be greatly appreciated.
I am assuming you want something like Gmail app where when you scroll a mail the header sticks on top... To do this, you need 2 views. You have your regular scroller below and overlay a fixed view on top (you can use a relative layout to do this). When your cell goes past a certain spot, you want to populate and set the visibility of the fixed view to VISIBLE. This would give the impression that the view you want to 'stick' to the top really just got stuck rather than scrolled out of view. You'll have to work out the opposite scrolling scenario too based on the location and height of the scrolled cell/view.
HTH

Is it possible to auto scroll In Android?

It is possible auto scroll in android? I want my layout to start scrolling when my user loads up the screen, is it possible to do without them having to touch the screen?
I don't think, there is a default method to solve this. However the ScrollView class (you probably need a ScrollView, to make the content scrollable) has a method, which enables you to scroll smooth through the content:
smoothScrollBy(int,int)
the first (x) value is the horizontal, and the second (y) value is the vertical scroll. You could use a background Thread to call this method with the desired parameters, until the end of your ScrollView is reached.

Vertical smooth scrolling of values in a text view

I have a text view where in i have to keep ages between 1-99. I also have two buttons ^ and v(i mean up and down arrows) on clicking them the values of the age should smoothly scroll to next or previous value.
I have been trying different ways but couldnt achieve smooth scrolling. Can anyone please give me any idea of how to achieve the task.
I think the easiest way is to simply put the TextView within a ScrollView, and let the arrows interact with the ScrollView, by using things like the fling method and playing around with the velocity parameter to suit your needs.
Use the animation framework.
When pressing down, start the 'down'-animation.
When pressing up, start the 'up'-animation.
Read more about animation here: http://developerlife.com/tutorials/?p=343
View animation is not much matured and hence i am noy sure if that can be used for moving the views.
Please find the description below:
Another disadvantage of the view
animation system is that it only
modified where the View was drawn, and
not the actual View itself. For
instance, if you animated a button to
move across the screen, the button
draws correctly, but the actual
location where you can click the
button does not change, so you have to
implement your own logic to handle
this.
Source
To scroll smoothly you can try using the scroller component.
Reference
What you would need to do is pass the duration of the scroll in the constructor and then use the property
setFinalY(int newY)
to increment the counter position by 1 unit (equal to the height of the item).
Please let me know if that helps!

Categories

Resources