2017-12-04 3 views

답변

1

제약 조건을 사용하여 요소 2를 정렬 할 수 있습니다. 요소를 가운데로 맞추려면 왼쪽면을 요소 1의 왼쪽으로 제한하고 오른쪽 면도 동일하게 적용 할 수 있습니다. 그래서 xml에서 다음과 같은 형태가됩니다 :

<Element2 
    android:id="@+id/element2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:layout_constraintLeft_toLeftOf="@+id/element1" 
    app:layout_constraintRight_toRightOf="@+id/element1" /> 

가로로 가운데 정렬해야합니다. 또한 세로로 가운데에 놓고 싶다면 상단 및 하단 구속 조건을 추가하십시오.

편집 : 당신이 다른 요소의 중심 요소의 왼쪽을 정렬 할 경우 오해 질문, 당신은 GuideLine

그것이 Element1이의베이스 라인 기준의 가이드 라인 및 위치를 만들고 사용할 수 있습니다

<android.support.constraint.Guideline 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:layout_constraintBaseline_toBaselineOf="@+id/element1"/> 

그런 다음이 솔루션은 다음과 같은 한 가이드 라인

<Element2 
    android:id="@+id/element2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:layout_constraintLeft_toLeftOf="@+id/guideline" /> 
+0

@ktamas 문제 없어! :) 작동한다면 답변을 수락하십시오! 고맙습니다. –

+0

죄송합니다. 제 질문이 아니 었습니다. 귀하의 답변은 다른 하나의 아래에 전체 콘텐츠를 중심으로하지만, 내 질문은 다른 하나의 중간에 왼쪽 가운데로했다. – ktamas

+0

@ktamas 죄송합니다. 질문에 대한 오해가있었습니다. 나는 원래의 대답을 편집했다. –

0

에 element2에 왼쪽 정렬 : 대신의 가이드 라인, 다음 layout_constraintLeft_toLeftOf & layout_constraintRight_toRightOf 속성 element1의 중심에 위치가이 View 가이드 라인에 element2를 정렬 지침으로 1 픽셀의 *의 1 픽셀의 View를 사용

<android.support.constraint.ConstraintLayout> 
    ... 

    <TextView 
      android:id="@+id/element1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    <View 
      android:id="@+id/guideline" 
      android:layout_width="1px" 
      android:layout_height="1px" 
      android:background="#00000000" 
      app:layout_constraintLeft_toLeftOf="@id/element1" 
      app:layout_constraintRight_toRightOf="@id/element1" /> 

    <TextView 
      android:id="@+id/element2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      app:layout_constraintLeft_toRightOf="@id/guideline" 
      app:layout_constraintTop_toBottomOf="@id/element1" /> 

    ... 
</android.support.constraint.ConstraintLayout> 
관련 문제