2017-09-21 19 views
2

그림에서 알 수 있듯이 텍스트가 벽에 없습니다. 이것은 기괴한 행동 내가 듭니다 버그에게 생각Android ConstraintLayout TextView가 화면에서 벗어납니다.

Here'sa 화면 촬영 :

enter image description here

Here's 헤더 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> 

는 어떻게 만들 수 있습니다 TextViewstreet_name라는 텍스트가 화면 외부로 나오지 않습니까? 나는 MaterialDrawer을 사용한다. 그러나 나는 이것과 관련이 없다고 생각하지 않는다. 기기는 Android 6.0.1을 보유한 삼성 Note 4입니다. 2.3.3

답변

4

설정 android:layout_width="0dp"합니다. 그러면 제약 조건과 일치하게되고 경계 내에서 유지해야합니다.

작동하지 않습니까? street_name은 오른쪽에 guideline30에 의해 395dp에 의해 제한됩니다. 395dp이 화면 오른쪽에서 벗어 났습니까?

+0

nop not working – Erik

+0

@Erik 업데이트 답변. – Cheticamp

+0

잘 작동하지 않습니다. android : layout_width = "0dp"'가 설정되었습니다. 359dp는 어디서 얻었습니까? – Erik

0
당신의 <TextView android:id="@+id/street_name"...> 사용한다 android:layout_width="0dp"를 들어

그렇게 보이는 것을 android:layout_height="wrap_content" 안드로이드 스튜디오에서 ConstraintLayout 버전 com.android.support.constraint:constraint-layout:1.0.2를 사용하여 같은 :

<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"/> 

수정 # 1 : 나는 당신이 당신의 텍스트 뷰의 오른쪽을 제약 조건해야 추측 부모가 아닌 지침에 따라 변경하십시오. 즉 app:layout_constraintRight_toLeftOf="@+id/guideline30"에서 app:layout_constraintRight_toRightOf="parent"으로 변경하십시오. 결과적으로 당신은 : street_name에 대한

<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"/> 
+0

nop이 작동하지 않습니다. "android : gravity ="center "'가 조커 였지만 잠깐 생각하지 못했습니다. – Erik

+0

@Erik 위의"Edit # 1 "을 참조하십시오 ... –

0

오른쪽에 TextView를 첨부하면 모두 정상입니다. 뷰를 다른 뷰 또는 상위 뷰에 첨부 할 때 constraintLayout을 더 잘 사용하는 경우 4 가지 제약 조건을 모두 사용해야합니다.