• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Views order in LinearLayout

garrydias

Newbie
Hello, dudes

I have a problem with LinearLayout and want to solve it with API properties and not with a specialized solution:

- My main.xml has a LinearLayout (named topLayout and orientation=vertical) inside a root LinearLayout;

accihbgzehdblrhe.jpg


- In java code I did topLayot.setGravity(Gravity.RIGHT), because I want all ImageView inside topLayout at right side like following picture:

accihdazegxjnnbg.jpg


My problems is there. Instead of LinearLayout insert my imageView0, imageView1 and imageView2 in shown order (index 0 at right of the list), the imageView0 is always at the left of the list, like shown below:

accihhhzhmxojjdp.jpg


The Android API has solution for my issue?? Or have I to developer voodoo logic to solve it?

rgs
moz-screenshot-3.png
moz-screenshot-4.png
 
Depending on how you are adding the ImageViews to the LinearLayout, you can simply add a variable that defines where it should be placed among the LinearLayout's current children. In this example I am placing a inflated view (called "inflate" ) in the 1337th position in the LInearLayout:

Code:
layout.addView(inflate, 1337, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

Then you can just keep an integer variable updated in any way you want, to place it where you want it. In your case, as you want the latest added to be the first in the list, you could simply insert 0 as the place variable. Remember that it should never be larger than the number of children in the LinearLayout at the time of adding -1 as the children are indexed from 0...
 
Thnx JamTheMan....

In my original project I used this variable (I called pseudo index) but (in a little complex approach where TableLayout is used) take care of this pseudo index to reorganize the view
 
Back
Top Bottom