dracraft
dracraft

Reputation: 85

How can I place two TextView on a same line, in a vertical layout

I am trying to display an ImageView with 4 textView. "Title" "times" "age" and "informations". All of them are in global horizontal layout. And the 4 textView are in a vertical layout. The thing is that I want to have "times" and "age" one the same line. But it can't be with a vertical layout. Here is my xml code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
    android:id="@+id/imgLink"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" />



<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

     <TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Titre"
    android:textSize="8sp" 
    android:textStyle="bold" />

    <TextView
    android:id="@+id/time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="8sp"
    android:text="age" />


    <TextView
    android:id="@+id/age"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:textSize="8sp"
    android:text="age" />

    <TextView
    android:id="@+id/information"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="end"
     android:textSize="8sp"
    android:text="phrase" />

</LinearLayout>

Thanks

Upvotes: 8

Views: 20495

Answers (4)

jennifer
jennifer

Reputation: 9

Use the Graphical Layout, and place the age and the time fiels on the same ligne..much easier

Upvotes: 0

Dheeresh Singh
Dheeresh Singh

Reputation: 15701

as I told there is one more approach using Relative layout the second one

 <TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="8sp"
android:textStyle="bold"
android:layout_alignParentTop="true" />

<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="time"
android:layout_below="@id/title" />


<TextView
android:id="@+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
 android:textSize="8sp"
android:text="age"
android:layout_below="@id/title" 
android:layout_toRightOf="@id/time" />

<TextView
android:id="@+id/information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
 android:textSize="8sp"
android:text="phrase"
android:layout_below="@id/time" />

Upvotes: 0

Vipul
Vipul

Reputation: 28093

Here you go

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imgLink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Titre"
            android:textSize="8sp"
            android:textStyle="bold" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Time"
                android:textSize="8sp" />

            <TextView
                android:id="@+id/age"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="age"
                android:textSize="8sp" />
        </LinearLayout>

        <TextView
            android:id="@+id/information"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:text="phrase"
            android:textSize="8sp" />
    </LinearLayout>

Upvotes: 6

user370305
user370305

Reputation: 109237

Put LinearLayout as a parent to both textviews and set orientation of that LinearLayout as Horizontal..

<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
    android:id="@+id/time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="8sp"
    android:text="time" />
<TextView
    android:id="@+id/age"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="8sp"
    android:text="age" />

<LinearLayout/>

Upvotes: 3

Related Questions