I am trying to implement youtube like tabs.
Is there a way to achieve this with CoordinatorLayout, AppBarLayout and TabLayout ?
I already tried to change AppBarLayout height in onScrollListener in fragment, but it is causing some scroll flickering.
Youtube tabs
Definitely there's a way to do it. That's what AppBarLayout was born to do -- stuff like that.
But if you're trying to change the AppBarLayout height in an onScrollListener in a fragment, you have run far afield from the way those components are supposed to work.
Be forewarned that these components are fragile as heck, just barely do what they are supposed to do, are not well documented and they break easily. Doing something like hammering away at the AppBarLayout height would go far beyond "breaks easily", and venture well into the realm of "that's not really how it's supposed to work at all".
Putting the ListView (or RecyclerView) in a fragment may also go horribly wrong for all kinds of fairly obvious reasons relating lifecycle and order of instantiation of views.
I would suggest starting with a working sample for AppBarLayout, and moving your way forward incrementally from there. If you're using Android Studio, right click on your app folder, and select New/Activity/ScrollingActivity, and work your way from there.
Whether you can drive the AppBarLayout from a ListView or RecyclerView in a fragment or not, I couldn't say. I think you should be able to do that; but I'd suggest that you get a dummy listview working as a direct child of the activity first, and then try migrating it to a fragment afterward.
Expect it to be hard. And expect that you'll have to live with limitations of inflexible implementation. They do what they do. And do not like to do what they don't do.
Related
Let's say we have a BottomNavigationBar with a FAB on top. When using this setup and showing a Snackbar, the Snackbar should appear above the BottomNavigationBar and push up/down the FAB while appearing/dismissing.
This is a common scenario for the use of CoordinatorLayout. Is it also possible to create this animation using the new MotionLayout?
There is an issue in the bug tracker, but it's already closed, because OP didn't clearly formulate the question (https://issuetracker.google.com/issues/112665540)
Problems I ran into while trying: We don't have access to the layout-id of the Snackbar. We also don't have access to the general xml of the Snackbar, so we cannot set its Constraints.
UPDATE: I understand that a piece of code would help as a starting point to answer this question. But what ever piece of code I came up with yet, was not useful at all. I pinpointed now the 2 main problems:
I do not know the layout-id of the Snackbar. Therefore I cannot use it in writing a Scene description.
Even if I could create a Scene description (e.g. State1: SnackBar visible, State2: Snackbar not visible). I'd have to trigger these Scene transitions by hand. That means that I would re-create my own Snackbar instead of using the original Snackbar as it is intended.
COMMENTS: #mikejonesguy Yes, in my opinion they are similar. Not the same, but similar. And MotionLayout does also have the job you described: to coordinate interactions among its subviews. Replace "coordinate" with "animate" and you'll see my point. Also have a look at the OnSwipe/OnClick handlers. MotionLayout is still very fresh, but I think it will replace CoordinatorLayout in the future the same way ConstraintLayout replaced RelativeLayout. Maybe I'm wrong, maybe not...time will tell.
CONCLUSION:
As far as I'm concerned, there seems to be no way (yet) to achieve what I want only by using MotionLayout. If it's possible one day, I'll update this question with a working example. Sorry for the impossible bounty... :)
You can design your layout files as if the snackbar is in your layout hierarchy. You need to make use of Constraintlayout's virtual helper objects. Virtual objects are invisible but they act as a regular view during measuring & layout, therefore their purpose is to help you create the exact positioning you want.
A snackbars default height is min 48dp and max 80dp. You are going to need this information.
I need to fit several tables of data on a screen. For small screens, I though the best way to handle this, as a simple solution, was to have them all stacked up on top of one another. And then just to scroll down an view each table as you go down.
The tables of data need to be created with some kind of repeating, data-bound control. It seems like the ListView is the one to use with Android (but I'm open to suggestions).
The thing I am bumping up against is that you can't seem to have ListViews inside a ScrollView (note: I want to support KitKat). The rationale being that you can't have a scrollable control inside a scrollable control.
Is there any simple way of doing this? At this stage, I was hoping there'd be a simpler solution than going for the ViewPager swipe right option.
Thanks
Using the ExpandableListView solved my ux dilemma here. Or rather, the MvxExpandableListView.
I'm trying to design an app with a layout that will roughly look like this (don't mind the color):
How can I achieve something like that? I'm thinking of using a CardView for that bottom panel (I don't know what it's really called).
Furthermore, I want to hide it (animating it) when the use scrolls on the content. I have tried many codes but they won't work so I won't put them here anyway (like what's suggested here). Thanks for the help.
Whenever I have a question along the lines of "How do I do this neat UI thing I saw once?", I always start by checking out wasabeef's amazing UI library collection. In your case I might start by looking at bottomsheet or AndroidSweetSheet.
as you can guess from the title I wanted to reproduce the behavior I have seen in apps like Telegram v2.3.2 (Settings activity).
In this paricular case the Toolbar starts from an initial size and then adjusts its height (and also scales down the views in it) down until it reaches the 'normal' height of a common Toolbar according to the scroll that happens throughout the main content of the activity. How to achieve that?
As i was starting from scratch I've searched the web and found ManuelPeinado's gist which derives from FadingActionBar project, it hosts a View called ObservableScrollView which can monitor for the scroll events. I thought I could resize the toolbar when onScroll is called, but I didn't figure out how to achieve the result.
I also found that Telegram sources are available, which I think it's supercool but they are pretty difficult to read as they are complex, and I can't identify which part of code is responsible for what.
Any advices on how to implement this functionality, or some other resources from the web?
Thanks in advance.
Android-ObservableScrollView is a library which helps build this functionality.
It supports:
ListView
ScrollView
WebView
RecyclerView
GridView
I'm trying to find out what technique I have to use with my intended approach.
I have a layout that should consist of 3 parts: a top and right part that stay the same and a left part that can change in runtime. When the user decides to change this left part, it should display another layout at that location.
So far I've found these approaches:
ViewFlipper
Not really what I'm looking for since it's used by sliding your finger to the side instead of pressing a button
ViewPager
Seems to be pretty much the same as the ViewFlipper.
ViewStub
Can only be used once so not a viable option (I want the user to be able to change back and forth).
Sadly, none of them do the job (unless I have misinterpreted something). Is it even possible to do what I want?
If it's something not too complex, you could go with ViewAnimator.
For something more advanced Fragments are the solution.
Note: You could call setDisplayedChild() on a ViewFlipper to programmatically switch between views.
You could also call setCurrentItem() on a ViewPager (which by the way can use Fragments).