How to place two TextViews on the same line in a vertical layout

I am trying to display an ImageView with 4 textView. "Name" "times" "age" and "information". All of them are in the global horizontal layout. And 4 textViews are upright. The fact is that I want to have the "time" and "age" of the same line. But it cannot 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

+6
source share
4 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> 
+4
source

Place LinearLayout as the parent for both text views and set the orientation of this LinearLayout to 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/> 
+1
source

as I said, there is another approach using the Relative layout second

  <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" /> 

0
source

Use a graphic layout and put the age and time when you are on the same ligne .. much easier

0
source

Source: https://habr.com/ru/post/918256/


All Articles