Search code examples
androidtextviewprogrammatically-created

Three textviews (side by side) below one textview(centrally positioned)- Android


This is my first question so pardon any convention I might have unknowingly overlooked.

Now, I want to create a long table in which each element has centrally positioned textview and below it, three textviews side-by-side. I have tried TableLayout, which makes the cells aligned (and I dont want that). I have tried LinearLayout which makes it appear either vertical or horizontal, not the kind of mixture of both that I need. I tried RelativeLayout which happens to be too cumbersome and I still couldn't get my result. Most probably, am making a conceptual mistake somewhere. All this is to be done programmatically. Can somebody help?


Solution

  • How about putting a TextView and a Horizontal LinearLayout containing three TextViews in a Vertical LinearLayout or a RelativeLayout?

    <RelativeLayout>
        <TextView
            android:id="@+id/txt"></TextView>
        <LinearLayout 
            android:orientation="horizontal"
            android:layout_below="@id/txt" >
            <TextView></TextView>
            <TextView></TextView>
            <TextView></TextView>       
        </LinearLayout>
    </RelativeLayout>
    

    OR

    <LinearLayout
        android:orientation="vertical">
        <TextView></TextView>
        <LinearLayout 
            android:orientation="horizontal">
            <TextView></TextView>
            <TextView></TextView>
            <TextView></TextView>       
        </LinearLayout>
    </LinearLayout>
    

    Hope this helps.

    P.S: I haven't added id, width, height, text etc. :) Just a structure.