简体   繁体   中英

TextView text is not being wrapped

I am trying to create a layout as shown below (which is a horizontal collection of vertically stacked image and its name). And want the name to wrap if its longer than the image.

-------------------------
 ______                       
|      |
|      |
--------
This text
should wrap
-------------------------

I am using the code below. The layout looks good, but the text below does not wrap around. What am I doing incorrectly? Would appreciate a reply

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

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

        <ImageView
            android:id="@+id/multi_item_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:src="@drawable/some_img"
            android:layout_gravity="center"/>

        <TextView
            android:id="@+id/multi_item_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:text="Some Long name"
            android:scrollHorizontally="false"
            android:maxLines="2"
            android:layout_gravity="center"/>
    </LinearLayout>

</LinearLayout>

Ended up using Relative Layout with these attributes

        android:layout_alignRight="@+id/multi_item_image"
        android:layout_alignLeft="@+id/multi_item_image"
        android:layout_below="@+id/multi_item_image"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM