2017-09-21 49 views
2

画像のように、テキストは壁から外れています。これは、このような奇妙な行動であると私はit'saバグ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を搭載したsamsung Note 4です。 2.3.3

答えて

4

street_nameためandroid:layout_width="0dp"を設定します。それは制約と一致するようになり、境界内に保持する必要があります。

street_nameguideline30で右側に拘束されています(395dp)。 395dpは画面の右側にありますか?

+0

nop not working – Erik

+0

@Erik更新された答え。 – Cheticamp

+0

うまく動作しません。アンドロイド:layout_width = "0dp" 'が設定されています。あなたは359dpをどこから手に入れましたか? – Erik

0
あなた <TextView android:id="@+id/street_name"...>あなたが使用する必要があります android:layout_width="0dp"については

ので、それが見えることandroid:layout_height="wrap_content"のAndroid Studioで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"/> 

EDIT#1:私はあなたのTextViewの右側を制約必要がありますね親によって、指針ではなく、app:layout_constraintRight_toLeftOf="@+id/guideline30"からapp:layout_constraintRight_toRightOf="parent"に変更してください。あなたが持っている結果:

<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が機能しません。 「アンドロイド:重力=「中心」はジョーカーではありませんでしたが、 – Erik

+0

@Erik上の私の「編集#1」を参照してください... –

0

TextViewを右側に貼るだけでOKです。ビューを別のビューまたは親に追加するためのconstraintLayoutのより良いプラクティスを使用する場合は、4つの制約すべてを使用する必要があります。

関連する問題