Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text is being clipped off inside Constraint Layout android

I use the below layout to achieve a view with image on the right end of a constraint layout, and a text to the left of the image:

<LinearLayout
 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:orientation="vertical" 
         android:layout_width="match_parent"
         android:layout_height="match_parent">

  <android.support.constraint.ConstraintLayout             
    android:id="@+id/parentPanel"             
    android:layout_width="wrap_content"             
    android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/image"
                 android:layout_width="64dp"
                 android:layout_height="64dp"
                 app:layout_constraintRight_toRightOf="parent"
                 android:background="#ff0000"/>

            <TextView
                android:id="@+id/txt"
                android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="Lorem Ipsum is simply dummy text of the printing
 and typesetting industry. Lorem Ipsum has been the industry's
 standard dummy text ever since the 1500s, when an unknown printer took
 a galley of type and scrambled it to make a type specimen book"
                 app:layout_constraintTop_toTopOf="parent"
                 app:layout_constraintBottom_toBottomOf="parent"
                 app:layout_constraintRight_toLeftOf="@+id/image"
                 android:textColor="#000000"
                 android:textSize="20sp"/>
         </android.support.

constraint.ConstraintLayout>
     </LinearLayout>

I have attached the screenshot of the UI that has been obtained from above XML. The text is being clipped off on the left, when text is too long.

Screenshot_1

Screenshot_2

The dependency that is being used in build.gradle is:

compile 'com.android.support.constraint:constraint-layout:1.0.1'

like image 949
Rakesh Krishna Avatar asked May 04 '17 06:05

Rakesh Krishna


1 Answers

The problem was with your fixed width and height on your imageView (android:layout_width="64dp" and android:layout_height="64dp").

You can easily constraint you imageView using guidelines to give it size that relative to your screen.

All you need to do is fix your constraint :

<androidx.constraintlayout.widget.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:id="@+id/frameLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragments.MenusDesign.ExpandableCategoriesMenu.ExpandableCategoriesMenu">


<ImageView
    android:id="@+id/image"
    android:layout_width="64dp"
    android:layout_height="64dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:background="#ff0000"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/txt"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:text="Lorem Ipsum is simply dummy text of the printing
 and typesetting industry. Lorem Ipsum has been the industry's
 standard dummy text ever since the 1500s, when an unknown printer took
 a galley of type and scrambled it to make a type specimen book"
    android:textColor="#000000"
    android:textSize="20sp"
    app:layout_constraintEnd_toStartOf="@+id/image"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

like image 94
Tamir Abutbul Avatar answered Nov 15 '22 01:11

Tamir Abutbul