As you see in the picture the text is off the wall. This is such a bizarre behavior and I think it´sa bug
Here´sa screen shoot:
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
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?
Add the layconstraintEnd_toEndOf
and width 0dp
Setting width 0dp alone won't work
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
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, ie 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"/>
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.
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.