0

작동하지 않습니다문제 - 수직 마진 내가 ConstraintLayout를 사용하여이 간단한 레이아웃을 구축하고자

제목과 미묘한 그냥 한 줄의 텍스트 때 예상대로 작동

Layout with two text views

. 문제는 더 긴 텍스트와 함께 제공됩니다. 당신이 볼 수 있듯이, 제목 서로 미묘한 중복 :

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 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"> 

    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="#EEEEEE"> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="24dp" 
      android:layout_marginLeft="16dp" 
      android:layout_marginRight="16dp" 
      android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." 
      android:textAppearance="@style/TextAppearance.AppCompat.Headline" 
      app:layout_constraintTop_toTopOf="parent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="16dp" 
      android:layout_marginLeft="16dp" 
      android:layout_marginRight="16dp" 
      android:layout_marginBottom="24dp" 
      android:text="Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." 
      app:layout_constraintTop_toBottomOf="@+id/textView1" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintBottom_toBottomOf="parent" /> 

    </android.support.constraint.ConstraintLayout> 

</FrameLayout> 

그래서 문제가있다 : 여기

Results

내가 레이아웃에 사용하는 소스 코드는?


EDIT 1 2017년 10월 5일 오후 1시 19분

는 안드로이드 6.0 (API 23)을 실행하는 장치/시뮬레이터에서 재현 할 수있는 것 같다. API 21-22, 24+ 이상을 실행하는 기기에서 예상대로 작동합니다.

답변

1

에 대한

app:layout_constraintBottom_toTopOf="@+id/textView2" 

를 추가합니다. 그것으로, 당신은 이 TextViews 수와 FrameLayout이 당신이 직면하고있는 문제없이 ConstraintLayout 자체에 수직으로 중앙 :

API (23)에
<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" 
    android:background="#EEEEEE"> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="24dp" 
     android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." 
     android:textAppearance="@style/TextAppearance.AppCompat.Headline" 
     app:layout_constraintBottom_toTopOf="@+id/textView2" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintVertical_chainStyle="packed" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="24dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="16dp" 
     android:text="Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/textView1" /> 

</android.support.constraint.ConstraintLayout> 
+0

"포장 된"체인 스타일로 문제가 해결되었습니다. 감사! –

0

TextView1에는 더 낮은 경계가 없습니다.

단순히 당신은 당신에게 chaining option을주는 ConstraintLayout를 사용하는 것이 좋습니다 첫 번째 텍스트 뷰

+0

당신의 솔루션은 효과가 있지만이 특별한 경우에만 작동합니다. 텍스트 뷰 위에 ImageView를 추가하면 다른 이상한 레이아웃 문제가 발생합니다. 이 질문을보십시오. 예 : https://stackoverflow.com/questions/46588508/problems-with-constraintlayout-imageview-169-inappropriate-top-margin –

3

ConstraintLayout 버전 1.0.0 - beta5는, 그것은처럼 보인다 상단 여백이 존중되지 않거나 상단 TextView 높이가 올바르게 계산되지 않습니다. API 23에서는 중복되지만,이 버전이 ConstraintLayout 인 API 24에는 표시되지 않습니다.

그러나 ConstraintLayout 버전 1.1.0-beta2에서는 API 23 및 API 24에서 문제가없는 것으로 보였으므로 문제가 해결되었을 수 있습니다. 나중에 ConstraintLayout 릴리스로 업그레이드하여 문제가 지속되는지 확인하는 것이 좋습니다.

+0

1.1.0-beta2로 테스트했는데 예, 해당 버전에서 수정 된 것 같습니다. 그러나 아직 베타 버전이기 때문에 지금까지 사용하지 않는 것이 좋습니다. 생산을위한 것 같습니다 체인 = "포장"지금까지 사용하는 것이 좋습니다. –