I'm developing an App on Android Studio and I want to have an easter egg. To do this easter egg, I want people to click on the moon to unlock a new avatar.
The problem:
As you can see in the image, the background image is a whole horizontal scrollview and I can't make only a certain part of the horizontal view clickable. This leaderboard page shows up as it is shown on the schema 1 so if you move your finger in the arrow direction, you'll end up on the schema 2, because you've scrolled all the way to the left of the image.
What i've tried:
I tried do put the ImageButton inside de image scrollview, I tried to put the ImageButton inside the scrollview after and before the background image, I tried to put it outside the scrollview, after and before also, I tried to put a scrollview inside the existing scrollview, again, after and before the image.
My question:
How can I make it so that only the moon on the whole scrollview is clickable? Or is there a away to go around this problem and do this by other means? All help is acceptable, thanks!
Related
I'm trying to make horizontal scroll in TextView bRes programmatically. Reading some answers and tutorials, I've included some settings.
bRes.setHorizontallyScrolling(true)
bRes.setMaxLines(1)
bRes.setMovementMethod(ScrollingMovementMethod())
bRes.setScroller(Scroller(this))
I put in the left and right side of TextView, small left and arrows black triangles with a click event to make right and left scroll if text width surpasses the view width. The buttons just appears if they has some action to do.
When I set the text in TextView, I call this code
fun changeRes(t:String){
bRes.text = t
bRes.post{ bRes.scrollTo(0,0) }
val largu = bRes.getPaint().measureText(t)
bRight.visibility = if (largu > 0.99 * bRes.width)
View.VISIBLE else View.INVISIBLE
bLeft.visibility = View.INVISIBLE
}
I've selected put the text excess in the right side, i,e, when the text is wider than TextView, the left black arrow is invisible and the right black triangle is visible.
Well, with this the text disappears completely. If I comment the line
bRes.post{ bRes.scrollTo(0,0) }
the text appears again, but there is no scroll. I don't get to see the left excess characters. The bRes.scrollX value should by 200/300 pixes but is over 1 million!
The first parameter, according documentation, is the number of pixels invisible to left of the TextView.
PS: I've used exactly the same procedure to program a vertical scroll in another TextView and it works very well. I don't use ScrollView, I've directly programmed a scrolling in my another TextView.
PS 2: I've created all my layout dinamically. No XML for layouts.
Somebody has some help for me?
I have no idea about it, except put the text in TextView manually in each change.
What kind of layout are you using? It should not be a LinearLayout, but rather a FrameLayout or RelativeLayout
I've made a workaround that is working very well for me. It's sad that I haven't found a more direct way to do this:
a) I've put 2 triangle arrows inside 2 small buttons to the left and rigth of TextView.
b) The buttons are visible or not depending if has or not scroll hidden text in its respective direction.
c) I've used the event OnTouchListener to accept click in the scroll buttons or 20% of TextView width nearest to each arrow for getting more hidden text in that direction (I've made this because the arrows are small and prone to touching in a wrong place.
d) I have to keep inside a tag (extra field of the widget) a complete text value of the widget.
e) For calculating which text I have to put in a field, I've programmed a heuristic using
widget.getPaint().measureText(string)
The visual is something like this:
PS: The ideal isn't using horizontal scroll, but if it is necessary, I think that the above appearance is nice and it is practical for users. I don't like the marquee solution where text moves alone: thinking as user, it's annoying.
I am trying to implement a scrolling "newsbar". There is a RelativeLayout which fills the screen horizontally. It should contain many different news titles, contained by TextView objects, which I download from the internet and they should be animated in order to slowly moving from right to left, which will generate a "scrolling newsbar" effect. I place the first TextView as RelativeLayout.ALIGN_PARENT_LEFT and all the consecutive TextViews aligned as RelativeLayout.RIGHT_OF according to the previous TextView. So, the text would enter from the right side of the screen and flow through the layout and finally exit from the left side.
I see that the RelativeLayout clips children which are outside of its bounds. I set android:clipChildren="false" for this purpose but it does not function and the TextViews continue to get clipped, which is very annoying and is currently blocking my progress.
Is this a bug or am I doing something wrong?
Please help me...
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.
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
I have a ScrollView layout like this, for example:
<ScrollView>
<Component1>
<Component2>
<Component3>
<Component4>
...
</ScrollView>
Inside ScrollView I have some components, each of them can be anything like LinearLayout, RelativeLayout, TableRow, ...
Now what I want is I will scroll the view, when the <Component2> reach the top of the screen, it will be keep on the screen and <Component3>, <Component4>... will keep scrolling till the end of page. When I scroll down, <Component2> will only be scrolled when all the <Component3> has became visible. I saw this on an Iphone app and wondered how to achieve this on Android.
I don't know if I describe clearly enough but it is same like this video
http://www.youtube.com/watch?v=jXCrM1rzLZY&feature=player_detailpage#t=71s
When the tabs scrolled up to top, it stay there. And when scrolled down like in 1:36 of that video, it stay there until all the content below has became visible on the screen.
Does anybody know how to do this on Android?
I guess you could create a hidden copy of Component2 in a RelativeLayout that is setVisible(true) when the coordinates of Component2 are lower(Android draws from the top) than the top of the ScrollView. When the coordinates of Component2 are higher than the top of the ScrollView (.getTop()), Component2Copy.setVisible(false).
You may also want to disable them when changing their visibility. Good luck with this.