Android location - folding two text elements vertically inside a ListView row

I started with Fedor ListView . Here is the XML for my ListView element:

<?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"> <ImageView android:id="@+id/image" android:layout_width="50dip" android:layout_height="50dip" android:src="@drawable/stub" android:scaleType="centerCrop"/> <TextView android:id="@+id/name" android:layout_width="0px" android:layout_height="0px" android:layout_weight="0" android:textSize="20dip" android:layout_marginLeft="10dip"/> <TextView android:id="@+id/address" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="16dip" android:layout_marginLeft="10dip"/> </LinearLayout> 

What I see on my device is ImageView and two TextViews displayed sequentially from left to right.

What I want is an ImageView all the way to the right (this is already correct), the name of the TextView to the right of the image (this is correct) and the address of the TextView, BELOW is the name of the TextView. I could not figure out how to do it right.

Please note: I know that I can just add a new line to the name and include the address text after that, but I want these two elements to have different font sizes, so this is not an option. Thank you very much!

+4
source share
1 answer

You need to set the orientation of LinearLayout and achieve what you want to do, you will need to use several of them. In pseudocode, you will need:

 <LinearLayout android:orientation="horizontal" ...> <ImageView android:id="@+id/image" ... /> <LinearLayout android:orientation="vertical" ...> <TextView android:id="@+id/name" ...> <TextView android:id="@+id/address" ...> </LinearLayout> </LinearLayout> 
+6
source

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


All Articles