I have a ScrollView with a RelativeView beneath it. Within that RelativeView, there are 3 views in it. 2 of those 3 are initially hidden.
Even though on my phone the scroller_rel doesn't take up the whole screen, I can still scroll through as if scroller_rel2 and scroller_rel3 are there and not hidden.
Programmatically I will decide if scroller_rel2 and scroller_rel3 are hidden or visible, and I'm wondering how to also then decide if we should be able to scroll or not.
The easy way to ask this question is: How can I programmatically tell ScrollView the height of the visible contents, so that if the contents are not larger than the container, we disable scrolling, and if say 2 of the 3 are showing, how can we then enable scrolling only to the bottom of scroller_rel2?
The reason you're having this problem is because setting the view to be View.INVISIBLE does just that, but it still takes up space in your layout, so that's why you can still scroll. What you should be using is View.GONE, this actually sets the view to be invisible and it removes it from the layout. Check out the documentation here:
GONE
INVISIBLE
Related
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?
In my app I have a scroll view with n number of data to be listed out. There are two buttons one is named as UP placed above scroll view and the other is DOWN placed below scroll view.
Using the UP and DOWN buttons the list of views can be scrolled.
When the scroll bar is in top the Up button will be invisible and when the scroll bar reaches the bottom the DOWN button will become invisible, I have written logic for this using the getScrollX() method.
Now my problem is when there is very few data for example 3, the scroll bar will not be visible and the layout cannot be scrolled, in such a case both the UP and DOWN buttons need to be in invisible. How to do this, please suggest me a way?
You can try and use a ViewTreeObserver to check the dimension of the View inside your ScrollView. If the dimension exceeds a certain limit (such as the screen size), the ScrollView will be scrollable. See this preview SO answer for more details. Hope that helps!
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.
Does anyone know what android:isScrollCOntainer = (boolean) or $(View).setScrollContainer(boolean) do?
At first I thought this would be the answer to set a View inside a ScrollView NOT to scroll with ScrollView, but it doesn't seem to be the case.
On Android Developers it says,
"Set this if the view will serve as a scrolling container, meaning that it can be resized to shrink its overall window so that there will be space for an input method. "
Can anyone kindly explain what this description means?
What is a scrolling container in this case?
What kind of input method is available?
A scrolling container is one where the size of the container is independent of it's content.
For instance you can make a ScrollView or ListView of height 100 pixels, but you can fit as much content in as you want. Similarly regardless of the size of the content in the view, you can set the size the of the View to whatever you'd like.
If a container is scrollable, then Android knows it can shrink the size of the container without rendering parts of the content of the container inaccessible (since the user can just scroll down to see things not on screen). It uses this for when the SoftKeyboard is opened - if a container is scrollable it will shrink it as much as possible in an attempt to keep all of the elements on screen.
So ScrollView, ListView, GridView etc are all examples of scrolling containers.
I am looking in to the same thing and I am not sure exactly what it means either. The input method is however the soft keyboard. Changing it affects how the views resize when an edittext is clicked and the keyboard pops up. Look in to android:windowSoftInputMode for more information.
I hope this was at least a little bit helpful!