Kaan Karaca February 2016

How to add 3 column in 1 layout?

first of all, sorry for my poor English. I want to design a layout. If you look at the picture below you will understand what I am saying. In the second line, columns are dispersed.

I got this:

User   User  User
User User  User
User    User    User

I need:

User User User
User User User
  • Actual layout

  • What I want

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="TEST1"
        android:id="@+id/textView4"
        android:layout_weight="1"
        style="@style/diziKanals├╝reTextViews" />
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="TEST2"
        android:id="@+id/textView3"
        android:layout_weight="1"
        style="@style/diziKanals├╝reTextViews" />
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="TEST3"
        android:id="@+id/textView2"
        android:layout_weight="1"
        style="@style/diziKanals├╝reTextViews" />
    

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="Micheal Jackson"
            android:id="@+id/textView8"
            android:layout_weight="1" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="YEAR 2016"
            android:id="@+id/textView9"
            android:la        

Answers


Faruk Toptas February 2016

Set layout_width="0dp" if you want to use layout_weight. Your layout xml can be:

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

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="27dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="0dp"
    android:layout_marginTop="0dp"
    android:weightSum="3"
    android:orientation="horizontal">


    <TextView
        android:id="@+id/textView4"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="TEST1 asdjfga sdfa" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="TEST2" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="TEST3" />

</LinearLayout>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="27dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="0dp"
    android:layout_marginTop="0dp"
    android:weightSum="3"
    android:orientation="horizontal">


    <TextView
        android:id="@+id/textView42"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="TEST1 asdjfga sdfa" />

    <TextView
        andr 


uaBArt February 2016

Try this:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TableRow>
        <TextView
            android:text="Test"
            android:padding="3dip" />
        <TextView
            android:text="Test"
            android:padding="3dip" />
        <TextView
            android:text="Test"
            android:padding="3dip" />
    </TableRow>

    <TableRow>
        <TextView
            android:text="Test"
            android:padding="3dip" />
        <TextView
            android:text="Test"
            android:gravity="right"
            android:padding="3dip" />
        <TextView
            android:text="Test"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>
</TableLayout>

Use TableLayout, not LinearLayout


Markicevic February 2016

My advice is to use RecyclerView and set GridLayout as LayoutManager?

Post Status

Asked in February 2016
Viewed 1,452 times
Voted 8
Answered 3 times

Search




Leave an answer