I need to create something similar as shown in the image, Need some help as I've already tried many things and I'm out of ideas.
Can't post code, sorry about
Image URL:
https://imgur.com/a/bF7BEhv
(1) Initial State
(2) What I want, (even after revealing the recyclerview in the first view, the other views should stay in the screen)
(3) what actually happens
Each view on click expands or reveals a recycler view inside it
On expanding a view it shows a recycler view
Edit:
This is how I tried the layout to look like(code us abstract not exact):
<ConstraintLayout>
<CardLayout>
<TextView/>
<RecyclerView/>
</CardLayout>
<CardLayout>
<TextView/>
<RecyclerView/>
</CardLayout>
<CardLayout>
<TextView/>
<RecyclerView/>
</CardLayout>
</ConstraintLayout>
If you want to use 3rd party library, you can do this with MultiLevel Expandable RecyclerView.
Add the following dependency in your build.gradle file in your app folder:
dependencies {
implementation 'com.muditsen.multilevelrecyclerview:multilevelview:1.0.0'
}
Here is the detail description and documentation:
https://github.com/muditsen/multilevelrecyclerview
Related
<ConstraintLayout
app:clickListener="#{1}"> // wont work
<LinearLayout> // works here
<TextView/>
<ImageView/>
</LinearLayout>
</ConstraintLayout>
I have encountered a strange behaviour that I never met before. I am trying to make the constraint layout clickable so I have a binding adapter to init the click listener.
#BindingAdapter("clickListener")
fun clickListener(view: ViewGroup, data: Int){
view.setOnClickListener{
println("Click")
}
}
The constraint layout is not listening to my clicks. By chance, I created the linear layout, moved the app:clickListener="#{1}" from the constraint layout to linear layout. This will work and clicks are listened. If I remove the linear layout and add app:clickListener="#{1}" to either the Textview or ImageView or both, clicks are listened too. It just won't work no matter what at the root level.
Is there an explanation for this? I am trying to get rid of the linear layout as it adds a layer to the view but this is the only way that I can have to make it work and please note that I will only use binding adapter for this case.
Basically, I have a Scroll View and it contains several child inside Linear Layout. Now, I want to show a View constantly on the top of the screen when it is scrolled down.If it is scrolled up everything should be as it was earlier.
Can anyone just help me out? Any help would be appreciated! (Thanks in advance).
Define a ObservableScrollView class entends ScrollView.
Then write your layout xml like this:
<RelativeLayout>
<View/>
<ObservableScrollView>
</ObservableScrollView>
<RelativeLayout>
In ObservableScrollView class,focus on this onScrollChanged function.
Change the visibility of your target view by param 'y'.
I would like to reproduce this layout :
The blue lists are not scrollable, but the red panel (probably LinearLayout) is.
I already tried two ListView but I don't think it is the good way to do this, it doesn't work.
I read an article that advised to add multiple items to a LinearLayout. But in doing so, how to handle events on a single item, or use a BaseAdapter ?
I know I'm a little vague, but I'm having a little trouble explaining what I really want, I started Android development a few days ago.
Thanks.
I don't think it uses any ListView.
You can probably create something like this by having the red panel be a LinearLayout or RelativeLayout that's inside a ScrollView, so that it scrolls.
Then the blue "list" is probably not a ListView if it doesn't scroll. I guess it's just a bunch of regular views. So, something like this (pseudo code)
<ScrollView>
<LinearLayout>
<whatever layout for the green cell>
<include layout="blue_cell>
<include layout="blue_cell>
...
</LinearLayout>
</ScrollView>
And then you just create a layout for your blue cell, see info here: http://developer.android.com/training/improving-layouts/reusing-layouts.html
If you have a variable number of blue cells, you can just have the ScrollView and LinearLayout in XML, and inflate the blue cells layout programatically and add them to the LinearLayout
I have a relatively big XML layout (38 kB, 600 lines) with hierarchy like:
<ScrollView>
<LinearLayout>
<TabHost>
<LinearLayout>
<FrameLayout> //tab widget
<LinearLayout> //tab content
<LinearLayout> //section
<TextView> //section name
<LinearLayout orientation="horizontal"> //item 1 box
<TextView> //item 1 title
<Spinner> //item 1 picker
</LinearLayout>
<LinearLayout> //item 2 box
<TextView> //item 2 title
<Spinner> //item 2 picker
</LinearLayout>
... //18 other items
</LinearLayout>
... //4 other sections with 15 items each
</>
It is a data entry form that has to have that many items and the best I can do now is to do to wrap setContentView and loading of data to the spinners in an AsyncTask with a "Loading..." dialog.
Does extensive using of themes also slow down the view inflation? The view inflater wouldn't need to look in loaded theme.xml, but if I were to inline the theme into the layout xml, it would also increase the size of the XML considerably, thus slow down the parser.
Is there something I could do to simplify the layout that would make it load at least twice as fast?
I'm thinking that I might try to get rid of the horizontal LinearLayouts, and build the "section" with TableLayout.
First, three general comments:
You really want to avoid layouts that deeply nested.
Consider using RelativeLayout to replace nested LinearLayouts.
Use the layout_opt tool to get some suggestions on layout optimizations.
Now, more on #1 … have you considered writing your own layout? It sounds complex at first, but it can sometimes drastically improve layout performance. For example, if RelativeLayout doesn't serve the purpose, you may be able to combine your Linear-Frame-Linear-Linear chain into a single custom layout.
Lastly, is there a reason your tab indicators are scrollable? That seems like a navigation/UX problem.
The only thing I can think to do would be to break your views into a couple different parts and inflate each view whenever the user gets to that part. Not sure if that helps at all but good luck.
Also might help to look at that portion of the code in traceview
I am skinning an app and I was wondering if there was a way to keep common elements the same between XML layouts without copying the same code around all the time.
For instance, I have a header and footer and background that will be the same between most pages. Can I make a "common" xml containing the header and footer and just load the individual page like a frame inside of it?
I'm not sure how I would reference that individual page within the XML. Maybe I could change an ID from the java side in an onCreate function, although it seems like more work now, if I changed something on the header and footer in the future I wouldn't have to change every Activity of the app.
Thanks for any insight!
I think it's the inclue tag you're looking for. Example:
<include layout="#layout/bar_header_top" />
Make a Java class that extends a View that holds all header elements and one that holds all footer elements and implement them in every view like this
<LinearLayout>
<com.[package].[classname of header] />
-- content here --
<com.[package].[clasname of footer] />
</LinearLayout>