Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8867459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:02:16+00:00 2026-06-14T17:02:16+00:00

I am building an application that will add views to a relative layout until

  • 0

I am building an application that will add views to a relative layout until stopped.
My question is how does RelativeLayout.LayoutParams.addRule work? If I keep calling addRule will this create an ever growing list or does addRule check if a rule already exists? Is the following code really neccessary? Can I just use addRule and if already exists this will not create a duplicate entry?

Thanks

    int[] rules = this.position[0].params.getRules();
    boolean rule = false;

    switch(index){
    case 0:

        for(int i = 0; i < rules.length; i++){
            if(rules[i]==RelativeLayout.RIGHT_OF)
                rule = true;
        }

        if(!rule){
            this.position[0].params.addRule(RelativeLayout.RIGHT_OF);
        }

        break;
    case 1:

        for(int i = 0; i < rules.length; i++){
            if(rules[i]==RelativeLayout.LEFT_OF)
                rule = true;
        }

        if(!rule){
            this.position[1].params.addRule(RelativeLayout.LEFT_OF);
        }

        break;
    case 2:

        for(int i = 0; i < rules.length; i++){
            if(rules[i]==RelativeLayout.ABOVE)
                rule = true;
        }

        if(!rule){
            this.position[2].params.addRule(RelativeLayout.ABOVE);
        }

        break;
    case 3:

        for(int i = 0; i < rules.length; i++){
            if(rules[i]==RelativeLayout.BELOW)
                rule = true;
        }

        if(!rule){
            this.position[3].params.addRule(RelativeLayout.BELOW);
        }

        break;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:02:18+00:00Added an answer on June 14, 2026 at 5:02 pm

    By looking at the code for the RelativeLayout.LayoutParams class you can see that the rules are stored in an int array where the rules are the indexes, so the rules will be added only once no matter how many times you call addRule(the last call will count).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I'm building an application that will have over 30 models, and I want
I am building an application that will have a model that belongs_to another model
I am building a web application that will need to allow users to save
I'm building a WPF application that will be run on laptop computers mounted in
Background: I'm building a small application that will be run daily, pulling data from
Building an iPhone OS application that will allow users to anonymously post information to
I'm building a .NET CF 3.5 application that will communicate with an server based
I am building an ASP.NET web application that will be deployed to a 4-node
I am building a web application with Spring Security that will live on Amazon
Building a rails B2B application that will have various users. I'm pretty clear on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.