How can an AppBarLayout be prevented from expanding? - android-recyclerview

I have a layout that looks somewhat like this:
<FrameLayout>
<Scrollview (empty view, set GONE)>
<LinearLayout (loading screen, set GONE)>
<CoordinatorLayout>
<AppBarLayout>
<RelativeLayout scroll|enterAlways|enterAlwaysCollapsed>
</AppBarLayout>
<RecyclerView with layout_behavior set>
<NestedScrollView (variation of empty layout, set GONE)>
</CoordinatorLayout>
</FrameLayout>
In the AppBarLayout there is a horizontal RecyclerView with cells, then below the main RecyclerView contains a different kind of cell and scrolls vertically. This works great when scrolling - the AppBarLayout appears and disappears perfectly.
The problem comes when searching and limiting results in the two RecyclerViews. When either RecyclerView is empty, it should disappear - and so when the top horizontal RecyclerView is empty the whole AppBarLayout should disappear.
To achieve this, I am calling AppBarLayout.setExpanded(false) - which is working. However, after calling that if I scroll the vertical RecyclerView up or down the AppBarLayout expands and shows itself. I've also tried resetting the LayoutParams scrollFlags so that they are 0, which should disable scrolling. The AppBarLayout no longer scrolls - but it still expands.
How can I totally prevent an AppBarLayout from expanding? I need to close it, and force it to stay closed until I reset it no matter what the user does.

In another place I had a scroll listener set up to expand the view at the top. This was triggering the expand where it should not have.

Related

UICollectionView compositional layout not scrolling horizontal items back to beginning

When I try to refresh the data in my UICollectionView that's using iOS 13's new compositional layout, I can't find a way to make horizontally scrolling sections scroll back to their starting point.
If I call applySnapshot on the data source, the section's data refreshes, but it doesn't scroll back to the beginning. If I call scrollToRowAtIndexPath on each section, it will go back to the first row but it ignores the content insets on that section, which doesn't look good.
I tried applying an empty snapshot before applying the real one and that does work, but I intermittently get crashes in UICollectionCompositionalLayoutSolver saying "invalid section - null".
So what's the proper way to reset the horizontal scrolling on a collection view that's using compositional layout? I'm sure there's something I'm missing.
I am not sure about your question in detail, but I am doing an initial scroll to the current object using this method, that does beautifully center the scroll to object:
collectionView.scrollToItem(at: IndexPath(item: indexOfCurrent, section: sectionIndex), at: .centeredHorizontally, animated: true)

NSCollectionView loses scrollbars after changing minItemSize until view gets resized

I have an NSCollectionView with a vertical NSCollectionViewFlowLayout. I display rectangular icons in it.
I also have a slider in the UI, and when that changes, I adjust the minItemSize, which I then use in collectionView:itemForRepresentedObjectAtIndexPath: to create an equally sized NSImageView to the returned NSCollectionViewItem's imageView. Then I reload the view by invoking reloadData.
After that, the view shows the icons in the new size as intended.
The problem is, provided I have more data to show than fits into the current scoll view, that when the General System Preferences are set to Show scroll bars: When scrolling, the scrollbar disappears after reloading the collection view, and trying to scroll with the trackpad leads to a bounce that's telling me that the scroll view thinks that the content is just what's visible, nothing more to scroll.
But as soon as I resize the window, which also resizes the collection view inside, the scrollbars come back.
Curiously, if the System Prefs are set to Show scroll bars: Always, then the issue does not appear and the scrolling always works, and the scrollbars always remain visible.
I've tried a lot of things to trigger the re-calculation of the scroll view, such as invalidating the layout of the collection view's layout, the scroll view itself, its content view, and also tried to set their needsLayout to true. Nothing makes this work.
Update: The potential duplicate (NSCollectionView does not scroll items past initial visible rect), neither the collectionView.setFrameSize: nor the window.setFrame: suggestions work for my case (I tried adding these line before and after reloadData).
Even if I force a resize of the window like this, it doesn't bring the scrollbars back, only a manual dragging of the window edges does:
[self.collectionView.window setFrame:NSInsetRect(self.view.window.frame, 1, 1) display:YES];
Also note that in my case, initially the scrolling works, just not after resizing and reloading.
Another finding: When I call selectItemsAtIndexPaths:scrollPosition: after reloadData, then the scrollbar comes back. But only if I pass a non-empty NSSet for the paths. And since I may not have selected any items, this isn't a permanent solution.
If no other ideas come up, I'll try to make a demo project.
I've solved it:
I had to delay the call to reloadData, e.g. by calling it from within the block code of dispatch_async(dispatch_get_main_queue(), ^{ ... });
Before the fix, I did call reloadData right from the setSliderValue: handler, which is bound to the slider's value. It appears that this didn't go well together.

Objective C Tap Gesture no working after frame resize

I making an ipad application with screen split in half. Each side contains a container and each container holds UIView.
In the left uiView i have a uiScrollView with multiple elements (customs uiview) inside, like a grid but with scroll, and each element support tap gesture.
When i tap each element they work fine and behave like they are suppose to. lets say they do a NSLog(#"tapped!").
Problem comes when i resize either the entire view that holds the scroll view or the Container like so:
navigationVC.view.frame = CGRectMake(0,0, 338,768);
The tap stops working! But if i resize back to its original frame, tap starts working again.
navigationVC.view.frame = CGRectMake(0,0, originalWidth ,768);
I thought the problem would be the elements re-arrange when i resize the scroll view, but in fact its not.
The frame is being resized when i swipe the entire application either left or right.
EDIT:
Behaviour diagram: http://i.imgur.com/4vKpHLQ.png?1
EDIT2: didnt figure it out yet, but i see now that element bound's are changing when the frame is resized.
Got it!
Problem was that when i resized the scrollView the elements.Bounds where changing too. Then i went digging why... could only be something like a anchor... i then started to change a few properties on my XIB.
Under "Simulated Metrics", changed the "Size" drop-down from "Freeform" (add 150, 45) to "Inferred".
Forced the size on initWithCoder, compiled, and it worked.
Thanks Burhanuddin Sunelwala for trying to debug this with me.

Xcode UITextView Still not scrolling using storyboard

I am trying to initiate a scroll view in my UITextView and even though I seem to have selected the appropriate boxes, I can't seem to get the scrolling working. I have gone through multiple questions similar to this but none seem to have the answer.
I included an image of Xcode below:
Question 2: When I scroll down the majority of my text shows but the scrolling stops with two sentences or so left and I have to scroll down and hold it there to read. Any way I can fix this so it scrolls all the way to the bottom of the text?
Can you check the two boxes: Bounce Horizontally and Bounce Vertically and see what's happening? Sometimes your content are actually way bigger than your view, and they are touching a invisible outer box. If you can see they actually move, that means there is nothing wrong with touch or scroll, is just the view layout problem.
For the content issue, my guess is that the content size is not right, you can programmatically adjust it with textView.frame property, set it to a proper size, such as the frame of the window or the frame of the content, which are CGRect classes. Comment below to see if this can solve your second problem.
The text view will not scroll in storyboard, only the app. And the text view will scroll once the content in the text view exceeds the frame size.
If you're using iOS 7+, you can just turn on auto layout, pin each of the sides of the text view to the edge of its parent view, and it works fine without needing to do anything in code.

ListView in a metro app does not get its vertical scrollbar

I am not experienced in Windows Store (aka Metro) app XAML, so perhaps I am overlooking something simple, but according to books and samples, a vertical scrollbar is a natural part of a ListView control, and unless explicitly disabled will show up when there are invisible items in the ListView.
But on in the case of my app. I have a typical List/Detail page with items in the left pane - they are displayed fine, with scrollbar, and selected item details in the right pane. Selected item contains a collection of subitems, and they are supposed to be displayed with a scrollbar in case there are many of them. I have a simple ListView definition:
<ListView
x:Name="itemCollection"
Grid.ColumnSpan="1"
SelectionChanged="ItemListView_SelectionChanged"
ItemsSource="{Binding Elements}"
ItemTemplate="{StaticResource Custom80ItemTemplate}" />
Strange enough, I never see a scrollbar for this list. Only when I explicitly set its mode to "Visible", I can see a scroll bar, but there is nothing to scroll it with!
Obviously the program believes that the whole list is visible so scroll bar is unnecessary, but what can make it do such judgement?
I've finally fixed the problem. As most of such problems, the error was silly: a Grid control that owns this ListView had an extra (wrong) row definition that had Height property marked with asterisk, i.e. taking all remaining space. But the row that ListView was using had Height marked as "Auto", therefore it expanded to the whole size of its items and never activated its vertical scroll bar.
Try Setting the visibility to auto.