Maestro1024
Maestro1024

Reputation: 3293

how to get textview below another textview in row in android linear layout

how to get textview below another textview in row in android linear layout

I have a layout and I want to have 3 text items horizontally and 5 rows of items (and that is in a column, and I will have 5 columns). What I have in the example here I one of those columns.

My problem is I can't get text view 2 below textview 1. I want 3 to the right of 1 and that is working.

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="50dp" >

        <TextView
            android:id="@+id/TextView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Test Name" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@+id/TextView1"
            android:text="Test Name" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=".01"
            android:textAppearance="?android:attr/textAppearanceSmall" />

Upvotes: 0

Views: 1308

Answers (3)

Pierfrancesco Soffritti
Pierfrancesco Soffritti

Reputation: 1738

If I understand well what you asked, this should be what you need:

<TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

<TableRow
        android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content >

        <TextView
            android:id="@+id/TextView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Test Name" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=".01"
            android:textAppearance="?android:attr/textAppearanceSmall" />

</TableRow>

<TableRow
        android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@+id/TextView1"
            android:text="Test Name" />

</TableRow>

</TableLayout>

Upvotes: 0

A Honey Bustard
A Honey Bustard

Reputation: 3493

Try this :

<LinearLayout
    android:id="@+id/tableRow1"
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/TextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test Name" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test Name" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=".01"
        android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>

Upvotes: 1

Sarthak Mittal
Sarthak Mittal

Reputation: 6104

You don't need the TableRow tag, just place those TextViews directly under your LinearLayout and don't forget to set the orientation of your LinearLayout to vertical

Moreover, you are adding all the TextViews in one single row, that is why they are not appearing vertically.

Upvotes: 0

Related Questions