One "list" below another inside a ScrollView - android

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

Related

Better way to design layout for similar content in android

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.

Strike view with line [duplicate]

This question already has answers here:
creating a strikethrough text?
(14 answers)
Closed 9 years ago.
I wanna achieve an horizontal line that strikes a whole view inside a ListView, so I give the effect of striking the whole element in the listview.
How can I achieve this? I have found how to make a line below the view, but not over it.
This will create a strike out line on your view
<View
android:id="#+id/View_Strike"
android:layout_width="match_parent"
android:layout_below="#id/Layout_myRow"
android:layout_height="1dp"
android:background="#android:color/white" />
Now where you are designing a row layout for your listview. place this above view in such a way that it overlaps you Text View at the desired position in you Row Layout
and set its visibility Gone
Now depending on the Situation when you have to strike thru Your Item make its Visibility Visible
Surely is the solution !! i have used it in one of my app
Don't think there is a standard fast way of doing such a thing, but you can always create a view of fill_parent width and 1dp height and strike the whole view centering it relative to its parent.
make your custome view like stike image and make visible invisible as per your requirment over the current view
I have found the answer, if someone founds this useful:
Create a FrameLayout, inside of it I put the LinearLayout (with my TextViews) inside of it, and then a View with height=1dp width=fill_parent, and gravity of center.
The FrameLayout actually was created to make multiple layer views so it was the perfect thing.
Also for the details, in the listAdapter I make the View visible or gone.

Android: How to change Relative Layout to Scroll Layout

Hello i have an Relative Layout in Android, with EditTexts, TextViews, one Spinner and RadioButtons. It's a lot of things for only one screen, so i need to change for a ScrolView. When i try add the line in the first line and on the last Row, I have problems.
How can i add a scroll on my screen without lose all the layout I built so far?
so i need to change for a ScrolView
You do not need to change "for a ScrolView". You need to wrap your RelativeLayout in a ScrollView.
How can i add a scroll on my screen without lose all the layout I built so far?
Put a ScrollView around your RelativeLayout:
<ScrollView>
<RelativeLayout>
<!-- existing stuff here -->
</RelativeLayout>
</ScrollView>
As #CommonsWare has said, you can just wrap your current layout with a ScrollView.
Just keep in mind that a ScrollView must have only one child.

How do I layout a button bar with buttons of different heights?

How do I go about implementing a button bar with buttons of different shapes and heights? As an example (please excuse my poor drawing skills for this quick mockup):
The example bar has 3 buttons, with the middle button (3) a different shape and height than the other 2 buttons (1,2). The button bar will be a view that is included and merged into other views so as to seem to float on top of the parent view.
I was thinking of implementing buttons 1 and 2 into a layout, and then button 3 as another layout that I then merge with the first two button's layout.
like my previous comrades said, you need some kind of layout or container that can have a background (if you wish for button #3 to hoover above it) then use relative layout for mixing the two the disadvantage of this other than complexity is that youcannot relate to the other two buttons since they reside in a different layout.
More elegant solution may be to have a special background drawable that can:
have a method setCurrentHeight() that will specify the height the actual viewable section should have the rest will be filled with transparent color.
override it's own draw so just before it's drawing it will have a callback called, call back you can register yourself to.
then you can register the callback in your activity to take the current position of the #3 button and set the height accordingly, this way you are still with one layout with special drawable as background.
A customized LevelDrawable might do the trick.
I would layout this bar as follows:
A RelativeLayout as a container for the rest, with height set to wrap_content and alignparentbottom = true
An ImageView for the bar
2 Buttons with a transparent background (Button 1 and 2)
Button 3 is a custom Button with a custom Image of a trapezoid as background
So you will have a Layout similar to this:
<RelativeLayout
...>
<ImageView
.../>
<Button
... Button 1 />
<Button
... Button 2 />
<Button
... Button 3 />
</RelativeLayout>
I don't exactly know that this will work, and I can't test it, but you might give something like this a try; I believe it can all be done elegantly through XML.
Have a RelativeLayout (id:mainLayout) that will contain all of your views, wrap_content for both dimensions.
Have a blank View as your first child that will serve as your background bar
Set the View's background color/image to what you want; layout_width to fill_parent; layout_height to wrap_content; layout_alignTop="#id/leftButton"; layout_alignBottom="#id/leftButton".
Add an ImageButton for your center button (id:bigButton), wrap_content for both dimensions; layout_centerInParent="true".
Add an ImageButton for your left button (id:leftButton), wrap_content for both dimensions; layout_toLeftOf="#id/bigButton"; layout_centerInParent="true".
Add an ImageButton for your right button (id:rightButton), wrap_content for both dimensions; layout_toRightOf="#id/bigButton"; layout_centerInParent="true".
In my head, I believe this works, but I could be off. Regardless, something to think about, and I hope it helps you find a solution. :)
Better you can tablelayout with different button styles or relative layout for button "3"

Speeding up complex Android View Inflation

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

Categories

Resources