How to enable zoom in ScrollView? - android

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.

Related

Android animateLayoutChanges does not work properly for ScrollView with fillViewport true

I am trying to animate layout changes for a LinearLayout contained in a HorizontalScrollView with fillViewport=true. The idea is that I have a dynamic bar of buttons that should distribute to fill the available space, but if there are too many buttons you can start to scroll left/right to see them all.
This all works great, and using animateLayoutChanges=true on the LinearLayout works smoothly if the HorizontalScrollView has fillViewport=false, but as soon as it is set to true, jerky motions start to happen:
You will notice that the settings button jumps straight to its new position, while the right two buttons initially jump, but then animate a little to their final positions.
For me it seems relatively clear that the problem is that the extra x-offsets introduced by fillViewport=true are applied instantaneously, while the remaining shifting of the buttons is animated as normal.
Is there any way to get the animation to consider the effects of fillViewport=true as well?
Details only in case it matters: My HorizontalScrollView contains a LinearLayout that for each button contains a FrameLayout containing a Button (required in order not to stretch the button clickable area). I have tried applying animateLayoutChanges to the scroll view, to the frames, to the buttons, etc as well, but no combination seemed to make a difference.

How can I disable ScrollView scrolling if it's not needed?

My UI consists of a ScrollView that takes the top 50% of the screen and under that two buttons that are attached to the bottom of the screen; YES and NO. The content of Scrollview is text that for most phones does not fill up the visual area of the ScrollView. However sometimes the text can be longer, such that it fills beyond the visual area of the ScrollView, hence the reason I added the ScrollView.
My problem is this; even when the ScrollView has very little text and does not need to scroll to show all of its content it still scrolls. The user can scroll the content up a slight amount. I'd like the View to instead not allow any scrolling if all the content is visible.
Is there an easy way to achieve this? Or do I have to implement that myself?
You cannot disable the scrolling of a ScrollView. You would need to extend to ScrollView and override the onTouchEvent method to return false when some condition is matched. To get help with extending, please read the answers to Disable ScrollView Programmatically?

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

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

Scrolling in viewflipper

This is one of the intermediate screens in the app.
I'm using a viewflipper.
I'm setting this view using vf.setDisplayedChild(9); where vf is ViewFlipper object.
Referring to above screen-shot, if I reach upto country field (which I'm checking through isFocused()), the whole view should scroll by some pixels (equal to keyboard height).
If I hadn't used viewflipper, then I would have tried something like scrollTo(x, y).
But how do I scroll in viewflipper.
Any help appreciated.
You could place a ScrollView as the view inside of the ViewFlipper.
The only problem I think you may still run into is that the keyboard should automatically shift things up (in my experience it doesn't function properly while in fullscreen though). I'd try displaying that screen without the fullscreen enabled and you may find that your behavior is handled automatically.

Android: Keeping Image Visible Throughout Animation

Background:
I have an Activity that comprises four buttons that each take up a quarter of the screen.
It contains a horizontal LinearLayout that is divided in half by two vertical LinearLayouts as shown in the image below:
http://i.stack.imgur.com/P7Wd3.jpg
Desired Effect:
When I touch a button, I would like it to animate and fill up the entire screen.
Issue:
I have accomplished the animation aspect by changing X and Y scales from 1 to 2 onClick.
The problem is, however, that the animated button will not show when it leaves its parent LinearLayout.
Thoughts
I have tried making the non-animated buttons invisible, but the animated button will only show in its parent LinearLayout.
I know this problem would be solved if I had used a single LinearLayout, but I was unable to use the "layout:weight" feature to make each button take up half of both width and length.
So... How should I approach this issue?
I would appreciate any help :)
Try using a single RelativeLayout. Check this post for a nice example. You may have to setVisibility(View.INVISIBLE) for the other buttons.
Alternative:
Construct a RelativeLayout as above but put that as the only child
of a FrameLayout.
When animating a button, remove it from the RelativeLayout and add it to the FrameLayout specifying the gravity in the LayoutParams appropriately. This way the rest of the buttons will also be seen in the background during the animation.

Categories

Resources