Android wallpaper program layouts - android

When I look at several of the more popular android walpaper programs, (HD Wallpapers and the like), they all seem to have a very similar layout with 4 pictures in a 2 x 2 grid where each takes up approximately 1/2 of the parent's respective width and height. After not having a lot of success emulating this with various combinations of layouts and objects, I am trolling for a pointer. Anyone who could get me pointed in the right direction would be greatly appreciated. Is there a standard mix to achieve this sort of view?
Side note: Please be gentle, it's my first time... asking a question. ;)

You could use a GridView with android:numColumns=2.
You can see a GridView example here. You would set the height by manipulating the LayoutParams on the views that you put inside the GridView (via its Adapter).
If that doesn't float your boat and you're not doing much scrolling, you can always create a TableLayout with TableRows of 2 Views apiece, or a vertical LinearLayout containing two horizontal LinearLayouts of 2 Views apiece.
What have you tried already? Can you expand on your use case a little bit more? Do the images need to scroll? Can they be static? Will there be more than 4 images on a page?

Related

put large number of equally sized ImageViews in a row

Within a layout I want to put 11 equally sized (more or less quadratic) ImageViews in a row. Only one of them shall be displayed at a point in time. It is crucial that the ImageView number x starts EXACTLY at x/11 of the screen width. This might sound trivial, but after some attempts and research I'm not so sure anymore.
What I tried so far is using a horizontal Linear Layout, putting 11 ImageViews in it and applying
android:layout_width="0dp"
android:layout_weight="0.0909"
to each of them and set visibility to VISIBLE for one of them and to INVISIBLE for all others in the code. Unfortunately this solution is not really reliable and I see that the position of the ImageViews vary slightly.
Another attempt, using the displayed ImageView as thumb of a seekbar and setting the seekbar's progress to number x was also not great on all devices I tested.
What is the best practice here to get stable results? Thanks in advance.

GridView cells with different heights

I am creating an android app and I have a page that displays many cards at once. These cards have constant widths (so that two fit next to each other on the page) however they all have different heights. I want to display them in a grid formation where they fit together without any gaps like the notes app on the material design "Cards" page - http://www.google.co.uk/design/spec/components/cards.html#cards-usage -
(about 1/8th down the page). My question is, does anybody know how to do this? Any help would be appreciated.
Since we had RecyclerView, it's enough to setLayoutManager using StaggeredGridLayoutManager.
You can find more instructions here.
I have not implemented Gridview but I believe you want to manipulate its layouts, like in ListView. For a start, a link is at GridView. Look at setLayoutParams method. It will give you good ideas.

Android: Children in ScrollView proportional to the ScrollView

I have a ScrollView that I would like to have a variable number of children in. Easy game, use LinearLayout.
Now, I am looking for a way to make the widths of the children some proportion of the ScrollView itself (it is going to be placed in another auto-laid out view).
I have tried using LinearLayout weights (and weightSum) to keep them proportional to themselves, but then they just fill the ScrollView and don't allow scrolling.
I have android:fillViewport="true" set on the ScrollView so that it fills its container, but I can't seem to find a way to make the children some fraction of the ScrollView itself.
Basically I want ALL the children to have a fixed width of say a 3rd of the available space, so that while scrolling at most 3 items are shown, and they are proportional to the available space.
My thoughts are that I will need to create a CustomScrollView that extends ScrollView, and then #Override the onMeasure() method, is this the way, or is there an easier, more elegant solution (hopefully using the layout_weights engine already in LinearLayout)?
Any help would be much appreciated!
P.S. I had a beautiful picture drawn, but apparently you need 10 rep, lame to the n^th degree. I would love to have contributed to more questions on SO, but I need like 15 rep to vote up a question that helped me? That means I need to ask 15 questions, of which I can already find all the answers on here.

Android: how do I implement the following layout?

I want to have this layout in my Android app.
Requirements:
All rectangles should distribute evenly over the entire screen
The two rectangles on the bottom right should have the same height (so also distributed evenly)
I tried GridLayout but that won't let me stretch the children across the screen. I tried RelativeLayout without success. I tried nesting LinearLayouts with weights, it works, but I read that nesting weights is bad for performance. And finally, I tried TableLayout with weights, but it does not have something like "row span" like an HTML table so I cannot do the two rectangles in the bottom right corner like I want them to be (without nesting weights again).
Somebody, please help! How hard can it be? I don't know what to do here. I could implement my own ViewGroup or something to manually implement the layout. But it feels like this is something very simple, so I should be able to use standard layouts.
You are able to use GridLayouts to do such a thing, for some help fitting the screen I suggest you look at the following: How to make a GridLayout fit screen size.
Depending on what you are doing, nested weights with a series of Linear Layouts will not harm your performance too much, however it is is something extremely large like an intricate game or something of that nature I suggest using the GridLayout.

Android is it better to use a TableLayout or GridView

I am developing an app and I would like to have 12 ImageButtons (3 x 4). centered in the android screen and the center section of the screen where the ImageButtons are located to have a color or gradient background.
Is it best to do this with a TableLayout or a GridView... or maybe something else. I am a newbie to Mono and Android so any help is appreciated. I was hoping to do most of the layout in the designer, but I am not sure of the best approach.
Can anyone point me in the right direction?
I think GridView is better to use as it supports recycling of views. In case of TableLayout all the views remain in memory.
Even if the no of buttons increases, GridView will take care of it.
Make sure you are implementing view recycling correctly, or otherwise you may have a memory leak.
If there are only 12 buttons, a TableLayout would probably be simpler to implement because you don't have to mess with the adapter. If you need scrolling or the number of buttons may increase over time, you would probably be better off going with the GridView.
You may want to look into the GridLayout in the Android Support library v7. It is kind of like the TableLayout but seems simpler to do things like just wrap button into a set number of columns.

Categories

Resources