21

As you see in the picture the text is off the wall. This is such a bizarre behavior and I think it´s a bug

Here´s a screen shoot:

enter image description here

Here´s the header xml:

<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="wrap_content"
    android:background="?android:attr/windowBackground"
    android:orientation="vertical">

    <TextView
        android:id="@+id/street_name"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginStart="15dp"
        android:text="street name"
        android:textColor="?AppTheme.InformationText"
        android:textSize="14sp"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_marginTop="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="19dp"
        android:layout_marginLeft="0dp"
        app:layout_constraintWidth_default="wrap"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="@+id/guideline29"
        app:layout_constraintTop_toTopOf="@+id/guideline37"
        app:layout_constraintRight_toLeftOf="@+id/guideline30"
        app:layout_constraintHorizontal_bias="0.605"
        app:layout_constraintVertical_bias="0.0"/>

    <ImageView
        android:id="@+id/street_view_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:padding="6dp"
        android:scaleType="fitCenter"
        tools:layout_constraintLeft_creator="1"
        android:layout_marginLeft="0dp"
        app:layout_constraintLeft_toLeftOf="@+id/country_flag_image"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="0dp"
        app:layout_constraintRight_toLeftOf="@+id/guideline29"
        android:layout_marginRight="8dp"
        app:layout_constraintTop_toTopOf="@+id/guideline37"
        android:layout_marginTop="8dp"/>

    <ImageView
        android:id="@+id/country_flag_image"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginLeft="4dp"
        android:layout_marginStart="4dp"
        android:layout_marginTop="8dp"
        android:adjustViewBounds="true"
        android:paddingBottom="5dp"
        android:paddingLeft="5dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintTop_creator="1"
        />

    <de.hdodenhof.circleimageview.CircleImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/exit_image"
        android:layout_width="46dp"
        android:layout_height="46dp"
        android:layout_marginBottom="8dp"
        android:layout_marginRight="-4dp"
        android:src="@drawable/exit_custom"
        app:border_color="#FF000000"
        app:layout_constraintBottom_toBottomOf="@+id/street_view_image"
        app:layout_constraintRight_toRightOf="@+id/street_view_image"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintRight_creator="1"
        />

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guideline29"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.5"/>

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guideline30"
        app:layout_constraintGuide_begin="395dp"
        android:orientation="vertical"/>

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guideline37"
        app:layout_constraintGuide_begin="8dp"
        android:orientation="horizontal"/>

</android.support.constraint.ConstraintLayout>

How can I make the TextView called street_name text not go outside screen? I use the MaterialDrawer but I dont think that has anything to do with this. Device is samsung Note 4 having Android 6.0.1. Using ConstraintLayout version com.android.support.constraint:constraint-layout:1.0.2 in Android Studio 2.3.3

Cheticamp
  • 61,413
  • 10
  • 78
  • 131
Erik
  • 5,039
  • 10
  • 63
  • 119

5 Answers5

43

Set android:layout_width="0dp" for street_name. That will cause it to match constraints and should keep it in bounds.

Not working? street_name is constrained on the right by guideline30 at 395dp. Is 395dp off the right of your screen?

Cheticamp
  • 61,413
  • 10
  • 78
  • 131
  • it´s not working yea `android:layout_width="0dp"` is set. Where did you get the 359dp from? – Erik Sep 21 '17 at 20:05
  • @Erik Have you checked guideline30 to see if it goes off screen? – Cheticamp Sep 21 '17 at 20:06
  • wow when I put the guideline30 at procentare 80% it works...Thanks, there is so many variables..thanks for walking me trough this.. – Erik Sep 21 '17 at 20:14
29

Add the layconstraintEnd_toEndOf
app:layout_constraintEnd_toEndOf="parent"
and width 0dp
android:layout_width="0dp"

Setting width 0dp alone won't work

Saini Arun
  • 391
  • 3
  • 7
2

Use app:layout_constraintEnd_toEndOf instead of app:layout_constraintRight_toRightOf Also beacuse Right_otRight may display wrong in some situation

And use Start_toStartOf instead of Left_toLeft

Also like the others said set android:layout_width="0dp" 0dp means match constraint

Yang.L
  • 96
  • 7
0

For your <TextView android:id="@+id/street_name"...> you should use android:layout_width="0dp" and android:layout_height="wrap_content" so that it looks like:

<TextView
        android:id="@+id/street_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="15dp"
        android:text="street name"
        android:textColor="?AppTheme.InformationText"
        android:textSize="14sp"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_marginTop="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="19dp"
        android:layout_marginLeft="0dp"
        app:layout_constraintWidth_default="wrap"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="@+id/guideline29"
        app:layout_constraintTop_toTopOf="@+id/guideline37"
        app:layout_constraintRight_toLeftOf="@+id/guideline30"
        app:layout_constraintHorizontal_bias="0.605"
        app:layout_constraintVertical_bias="0.0"/>

EDIT #1: I guess you should constraint right side of your TextView by parent, not by guideline, i.e. change app:layout_constraintRight_toLeftOf="@+id/guideline30" to app:layout_constraintRight_toRightOf="parent". As a result you have:

<TextView
        android:id="@+id/street_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="15dp"
        android:text="street name"
        android:textColor="?AppTheme.InformationText"
        android:textSize="14sp"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_marginTop="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="19dp"
        android:layout_marginLeft="0dp"
        app:layout_constraintWidth_default="wrap"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="@+id/guideline29"
        app:layout_constraintTop_toTopOf="@+id/guideline37"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0.605"
        app:layout_constraintVertical_bias="0.0"/>
Eugene Brusov
  • 17,146
  • 6
  • 52
  • 68
  • nop not working. thought for a moment that `android:gravity="center"` was the joker but not – Erik Sep 21 '17 at 19:24
0

Just attach TextView to right side and all be ok. When you use a constraintLayout better practice to attach view to another view or parent, all 4 constraints should be used.