2016-09-28 8 views
3

私はAndroidスタジオ2.2にアップデートして、新しいUIビルダーでConstraintLayoutを使用し始めているので、解決できない問題があります。ConstraintLayoutとTextViewの問題wrap_content

ImageViewの右側にImageViewTextViewという単純なレイアウトがあります。 TextViewのテキストは、サーバーから動的に更新されます(このテキストの正確な長さはわかりません)。 TextViewは、ImageViewと画面の右側の間のすべての空きスペースを使用します。以前RelativeLayoutと私はTextViewandroid:layout_width="wrap_content" を使用し、それが働いた:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="116dp" 
     android:layout_height="178dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="16dp" 
     android:layout_marginTop="16dp" 
     tools:src="@drawable/pets"/> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/imageView" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_toEndOf="@+id/imageView" 
     android:layout_toRightOf="@+id/imageView" 
     tools:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque molestie tincidunt mi a gravida. Aenean faucibus a sapien ut consequat. Praesent sed placerat quam."/> 
</RelativeLayout> 

RelativeLayout (ScreenShot)

をしかし、私はConstraintLayoutを使用するとき、そこにはtextwrapされていないとのTextViewが画面の外に起こっています。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="116dp" 
     android:layout_height="178dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginTop="16dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:srcCompat="@drawable/pets"/> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="16dp" 
     android:layout_marginTop="16dp" 
     android:ellipsize="none" 
     android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque molestie tincidunt mi a gravida. Aenean faucibus a sapien ut consequat. Praesent sed placerat quam." 
     app:layout_constraintLeft_toRightOf="@+id/imageView" 
     app:layout_constraintTop_toTopOf="parent"/> 
</android.support.constraint.ConstraintLayout> 

ConstraintLayout (ScreenShot)

答えて

1

次みては?アルファ8はそれに関連する回帰を有していた。アルファ9にアップデートしてみてください(スタジオを再起動したり、例外が発生した場合はキャッシュを無効にすることを忘れないでください)。

+0

を確認することができ、RelativeLayoutと一緒にConstraintLayoutを使用しないでください!できます!ありがとう! – rbaloo

+0

それは働いていません。 alpha 9&ConstraintLayout 1.0.2をインストールしましたが、動作しません。コンテンツが画面外に出る – Amit

0

使用しているConstraintLayoutのバージョン

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.constraint.ConstraintLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ImageView 
    android:id="@+id/imageView" 
    android:layout_width="116dp" 
    android:layout_height="178dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="16dp" 
    android:layout_marginTop="16dp" 
    tools:src="@drawable/pets"/> 

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/imageView" 
    android:layout_marginLeft="16dp" 
    android:layout_marginRight="16dp" 
    android:layout_toEndOf="@+id/imageView" 
    android:layout_toRightOf="@+id/imageView" 
    tools:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque molestie tincidunt mi a gravida. Aenean faucibus a sapien ut consequat. Praesent sed placerat quam."/> 
    </RelativeLayout> 
    </android.support.constraint.ConstraintLayout> 
+0

あなたはうんこの記事https://stackoverflow.com/questions/37321448/differences-between-constraintlayout-and-relativelayout –

2

match_constraints(0dp)とちょうど同じで、wrap_contentと似ています。

<TextView 
    android:id="@+id/textView" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="16dp" 
    android:layout_marginTop="16dp" 
    android:ellipsize="none" 
    android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque molestie tincidunt mi a gravida. Aenean faucibus a sapien ut consequat. Praesent sed placerat quam." 
    app:layout_constraintLeft_toRightOf="@+id/imageView" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent"/> 

意味これはあなたのレイアウトは、それはあなたが設定した制約ごとのようなコンテンツだラップすることを意味します。

+1

この回答に投票してください。 1つの行の変更、魅力のように動作します。 – Yao

+0

これは正解です。 – korrekorre

関連する問題