Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConstraintLayout: Is it possible to make TextView to wrap the text when gets too long?

Tags:

android

I want the TextView to be able to warp its text when it gets too long.

I am using chain method for the layout. But didn't get what I want.

This is what it looks like:

enter image description here

This is what I want to achieve:

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical"
    android:background="@drawable/bg_trans_bg_light_top_bdr"
    android:orientation="horizontal"
    tools:showIn="@layout/fragm_edit_split">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/iv_user_photo"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_margin="16dp"
        android:src="@drawable/homer"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        app:layout_constraintVertical_weight="1"
        android:id="@+id/tv_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:text="This is a very long long long long name"
        android:textColor="#000"
        android:textSize="12sp"
        app:layout_constraintBottom_toBottomOf="@+id/iv_user_photo"
        app:layout_constraintEnd_toStartOf="@+id/v_space"
        app:layout_constraintStart_toEndOf="@+id/iv_user_photo"
        app:layout_constraintTop_toTopOf="@+id/iv_user_photo" />

    <android.support.v4.widget.Space
        android:id="@+id/v_space"
        android:layout_width="0dp"
        android:layout_height="1dp"
        app:layout_constraintEnd_toStartOf="@+id/tv_dollar_sign"
        app:layout_constraintStart_toEndOf="@+id/tv_name" />

    <TextView
        android:id="@+id/tv_dollar_sign"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="$"
        android:textColor="@color/text_light"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="@+id/et_amount"
        app:layout_constraintEnd_toStartOf="@+id/et_amount"
        app:layout_constraintStart_toEndOf="@id/v_space"
        app:layout_constraintTop_toTopOf="@+id/et_amount" />

    <EditText
        android:id="@+id/et_amount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="16dp"
        android:background="@null"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:gravity="center"
        android:inputType="number"
        android:textColor="#000"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/tv_dollar_sign"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="20.00" />

</android.support.constraint.ConstraintLayout>

By using RelativeLayout there is no issue. But I prefer ConstraintLayout.

like image 335
Arst Avatar asked Sep 06 '17 00:09

Arst


1 Answers

OK. Found out after 10 minutes. Just set the width to 0dp for the TextView..

like image 83
Arst Avatar answered Nov 03 '22 02:11

Arst