Help us understand the problem. What is going on with this article?

ConstraintLayoutでTextViewのWidthをAnySizeにしたら文字が欠けてしまう問題(constraint-layout:1.0.0-alpha4)

More than 3 years have passed since last update.

解決法

com.android.support.constraint:constraint-layout1.0.0-alpha5 以上のものを使う

build.gradle
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha5'

環境

  • AndroidStudio 2.2 Preview 6
  • com.android.tools.build:gradle:2.2.0-alpha6
  • com.android.support.constraint:constraint-layout:1.0.0-alpha4

問題

AndroidStudio 2.2 previewから新しく追加されたConstraintLayoutを使っていて、TextViewのWidthを中のTextによって可変 + 折り返して欲しかったのに文字が欠けてしまっていた

構成的にはこんな感じ

34e38678-c73e-e558-81cd-665ac530a3b2.png

layout.xml
<TextView
    android:text="hogehogehogehogehogehgoehogehgoehgoehgoeghoe"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:id="@+id/textView"
    android:textSize="18sp"
    android:scrollHorizontally="true"
    app:layout_constraintLeft_toRightOf="@+id/imageView"
    android:layout_marginLeft="8dp"
    android:layout_marginStart="8dp"
    app:layout_constraintTop_toBottomOf="@+id/textView"
    android:layout_marginTop="8dp"
    app:layout_constraintRight_toRightOf="@+id/comment_item"
    android:layout_marginRight="16dp"
    android:layout_marginEnd="16dp"
    app:layout_constraintBottom_toBottomOf="@+id/comment_item"
    android:layout_marginBottom="16dp"
    app:layout_constraintHorizontal_bias="0.0" />

これを実行すると、以下のように右端の文字が欠けてしまう

613f7c9c-6078-03cf-df12-5887d06b3b23.png

原因と解決法

com.android.support.constraint:constraint-layout:1.0.0-alpha4 のバグらしい
1.0.0-alpha5 で修正されたのでそちらを使う

現時点(2016/8/17)では 1.0.0-alpha7 が最新なのでそれを使ったら正しく表示された

build.gradle
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'

be779dbc-fd19-6153-b83e-6dd80b0e25dd.png

余談

ConstraintLayoutなどのAndroidSDK付属のtoolはgradleのdependenciesに書くだけではダウンロードされない
AndroidStudioのSDK Managerを開き、SDK Toolsタブで別途updateすると使えるようになる
ややこしいなこれ

0edba27d-e043-c04a-6eb3-5de3bd7f6b2f.png
6fcd44d6-90c9-399b-b1d8-e720a82a13d8.png

参考

http://stackoverflow.com/questions/38393954/wrong-textview-display-in-constraintlayout-when-anysize
http://stackoverflow.com/questions/37992187/gradle-sync-failed-could-not-find-constraint-layout1-0-0-alpha2

henteko
物を作ってます
https://henteko07.com
deploygate
毎日のフィードバックで、アプリ開発をもっと楽しく。DeployGateを運営しています。
https://deploygate.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした