Android check either scrollview is scrollable or not - android

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!

Related

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?

Make middle View not push other view outside of bounds

I have multiple TextViews inside a horizontal LinearLayout and i need the middle text view to have ellipse=middle so that when the middle text is long enough, it pushes on both sides but the other views don't go out of bounds, but instead the middle TextView shows the '..."
Here's how it should look.
Setting the items normally, wrap_content for all in a horizontal LinearLayout will make the at ASAP text be pushed outside of the screen on Android (the above screens are from the iOS app).
Any ideas on how to accomplish this? Perhaps with a ConstraintLayout somehow ?!
Yes, i would recommend a ConstraintLayout. Top item to the top of the view, bottom item to thr bottom of the view then the middle item attached to these two views. You could also use barriers.

Scroll linear layout beyond the content

I think that this is a simple question but I can't figure it out, I have a Scroll View with some text inside and it works perfectly, it only enables scrolling when the content doesn't fit into the screen. The thing is that I want to scroll the content no matter if it fits or not until the last line of the text reach the top of the view leaving blank space below and obviously "hiding" the content above it. I don't know if I'm explaining myself very well, thanks in advance!
Add a dummy view with height equal to the height of device's screen beneath your textview in scrollView.

ScrollView still scrolling with hidden contents

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

ScrollView that does not render views that aren't visible

I am attempting to improve the amount time it takes to fill the items into the ScrollView. If I hard code the height (not in pixels of course) of every RelativeLayout in the LinearLayout in the other LinearLayout in the ScrollView... can I get ScrollView to display the visible ones first and then when they are displayed to load up the rest later? The ScrollView should start off scrolled to a specific location.. not just the top of the screen. Now if we have to load from the top that is OK because there is about one third above the visible area and the rest below.
You could use ViewStub to inflate extra items only when you need it, but it sounds like you are describing what ListView does already.

Categories

Resources