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
Related
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
I have designed the red highlighted layout like the picture:
What I have used is LinearLayout with orientation. Here an ImageView and Two Textviews are repeated in four times. But as far my knowledge I designed it using LinearLayout. So I have to write every time the same design code for four times.
Is there any better way to design it so that I have to write it one time instead of four times.
My code for the highlighted portion is [here](https://pastebin.com/C9ZHDaZV).
Create one layout called for example weather_layout.xml and place your ImageView and Two Textviews inside, then just use include four times in your final LinearLayout like this:
<LinearLayout
... >
<include
id="+#/top_left"
layout="#layout/weather_layout"
... />
<LinearLayout/>
And then you can access like this:
LinearLayout topLeft = (LinearLayout) mainView.findViewbyId(R.id.top_left)
ImageView v = (ImageView) topLeft.findViewbyId(R.id.imageView)
Use Grid Layout. That way you won't need to handle the spacing and partitioning yourself. One line of of code will suffice.
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 searched a lot for this but doesn't find anything helpful. My question is I have about 13 textviews with text fields as given below. I want them to be in one activity so the user can scroll down to fill all the fields. Help me how to handle this.
Name
Organization
Country
City
Contact#
Address
Zip
Amount
Duration
Card#
Currency
Expiry Date
The XML layout you are looking for is the <ScrollView> although it can have one and only one child element. This means that you will wrap your <Linear/RelativeLayout> in the <ScrollView> so that your xml will resemble:
<ScrollView>
<LinearLayout> <!-- or <RelativeLayout> -->
<!-- all of your textviews and edit texts, etc. -->
</LinearLayout>
<ScrollView>
I would use a scrollview with the textviews in it so that the user can scroll down to see the rest of the information
What about using <ScrollView>?
You just have to surround the part of your UI you want to be scrollable in the xml with a ScrollView element...
http://developer.android.com/reference/android/widget/ScrollView.html
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>