Kaarel Purde
Kaarel Purde

Reputation: 1265

How to make dynamically created views line up vertically?

I have a LinearLayout. The button "go" is added with XML:

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView21"
    android:layout_marginTop="10dp"
    android:background="#0099FF"
    android:text="go"
    android:textColor="#FFFFFF" />

And the checkboxes dynamically:

for (final String str : strs) {
    CheckBox cb = new CheckBox(getApplicationContext());
    cb.setText(str);
    cb.setTextColor(Color.BLACK);
    thisll.addView(cb);
}

Currently elements line up horisontally: enter image description here

How to make them line up vertically?

Upvotes: 0

Views: 38

Answers (1)

Patrick
Patrick

Reputation: 1075

Have you tried adding orientation="vertical" to your LinearLayout?

Eg.

<LinearLayout
    android:layout_height="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <!-- The things you want aligned vertically go here -->
</LinearLayout>

Upvotes: 2

Related Questions