Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 428
dracraft Avatar asked Jun 16 '12 19:06

dracraft


People also ask

How do you do vertical linear layout?

To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .

Can linear layout be nested in relative layout?

Linear Layout can be used inside relative layout since one layout can be nested in other layout in XML.

Can we use one layout inside another layout?

To efficiently reuse complete layouts, you can use the <include> and <merge> tags to embed another layout inside the current layout. Reusing layouts is particularly powerful as it allows you to create reusable complex layouts. For example, a yes/no button panel, or custom progress bar with description text.

How do you go to the next line in TextView?

Just add a \n to your text. This can be done directly in your layout file, or in a string resource and will cleanly break the text in your TextView to the next line.


2 Answers

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>
like image 64
Vipul Avatar answered Oct 21 '22 16:10

Vipul


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/>
like image 33
user370305 Avatar answered Oct 21 '22 14:10

user370305