This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with RelativeLayout in LinearLayout

 
Marvin Serrano
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone!

I'm trying to create a bunch of RelativeLayouts inside of a LinearLayout, defined via XML. It would work well, except that I have to place one image beside another; hence the RelativeLayout issue (otherwise I'd just place a bunch of TextViews and stuff directly into the LinearLayout). The RelativeLayouts show, but each view I add to each RelativeLayout overlaps each other. For example, as you'll see in the following code, I call addView on the current RelativeLayout with three TextViews, an ImageView, and a Button, but they all overlap each other. Here's my code:



I apologize if there are a lot of commented-out sections; I've been toying with this for decades lol. If anybody knows how to place one View below another in a RelativeLayout, WITHOUT using XML (these are multiple instances of RelativeLayouts; since you can only call an XML RelativeLayout once from my experience, the layout must be done manually via Java ), please let me know.

Thanks in advance!

-Marvin

 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if anybody knows how to place one View below another in a RelativeLayout...

AFAIK, all the layout_below, layout_RightOf et al. attributes of a RelativeLayout that you find in XML are termed as "Rules" and there is a addRule() function in the RelativeLayout, if I am not mistaken. You can add any of these rules with addRule() function and have your views placed one below the other.

Also, can you use <Code> button and reformat(Edit) your original post, that way it becomes easier to read.
 
Marvin Serrano
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your prompt response!

I tried adding a rule to a RelativeLayout.LayoutParams variable, like so:

layoutparams_variable.addRule(android.widget.RelativeLayout.layout_below);

I'm guessing these rules aren't being passed outside of the method I'm calling? Because I'm adding the rule correctly I believe...argh lol.
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AFAICT, the way it works is:
You have a parent RelativeLayout and when you add Views(or ViewGroups) to it you call addView(view,params) variant of the method. If the params contain any rule these are applied to the child views inside this parent.
 
Marvin Serrano
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see...so for example, in my getnewRL method, I was right in defining those two RelativeLayout.layoutParams? Say if I have two textviews, and one of my layoutparams, call it layout1, has:

addRule(android.widget.RelativeLayout.ALIGN_PARENT_LEFT);

and the second one, layout2, has layout_below (something like that lol), and I say:

addView(TextView1, layout1);
addView(TextView2, layout2);

It should print out the first one to the left side of the parent, and the second one should be below the first one? Would these layouts be passed outside of my getnewRL method? Because I want to pass each RelativeLayout, with these parameters, to the onCreate() method, which adds these RelativeLayouts to a LinearLayout.

Sorry for all the questions, my internship has me working on this and nobody there knows how to program in Android
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic