Caleb Jones
Caleb Jones

Reputation: 32

View overlapping when using RelativeLayout Parameters

My RelativeLayout Dynamically adds check boxes and sets text to each of them but they all overlap each other even though i'm using the RelativeLayout.BELOW parameter.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bible_progress);
    Bundle progressBundle = getIntent().getExtras();
    int positionBook = progressBundle.getInt("position");

    if(positionBook == 0) {

        for (int i = 0; i < 10; i++) {
            RelativeLayout progressLayout = (RelativeLayout) findViewById(R.id.progress_layout);
            CheckBox progressBox = new CheckBox(this);
            progressBox.setText("Dynamic Checkbox " + i);
            progressBox.setId(i + 10);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.addRule(RelativeLayout.BELOW, progressBox.getId());
            progressBox.setLayoutParams(params);
            progressLayout.addView(progressBox);
        }
    }

}

Im not getting any errors so there is no stack trace.

Upvotes: 1

Views: 46

Answers (1)

Blackbelt
Blackbelt

Reputation: 157437

you are providing the wrong id to the rule

params.addRule(RelativeLayout.BELOW, progressBox.getId());

this way you are providing the id of the view you just created, to the rule

Upvotes: 2

Related Questions