ConstraintLayout에서 사용될 때 여백 (android:layout_margin*
)의 동작을 이해하는 데 문제가 있습니다. 여백은 특정 상황에서만 효과가있는 것으로 보이며 다른 사람이 나에게 설명해 주거나 (또는 ConstraintLayout 버그인지 확인하기 위해) 바라고 있습니다.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">
<View
android:id="@+id/leftView"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginEnd="20dp"
android:background="@android:color/holo_blue_dark"
app:layout_constraintEnd_toStartOf="@+id/rightView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<View
android:id="@+id/rightView"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/holo_green_light"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
...
, 나는 leftView
에서 여백을 변경할 때 rightView
...
<?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">
<View
android:id="@+id/leftView"
android:layout_width="0dp"
android:layout_height="100dp"
android:background="@android:color/holo_blue_dark"
app:layout_constraintEnd_toStartOf="@+id/rightView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<View
android:id="@+id/rightView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="20dp"
android:background="@android:color/holo_green_light"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
는 ... 여백이 예기치 않게 그렇다면 그 이유
사람은이가 예상 된 동작 여부를 설명 할 수 ... 사라?rightView
부모 (
ConstraintLayout
)에 의존하기 때문에
호기심에 leftView의 기존
layout_constraintEnd_toStartOf
제약 조건을 변경 :'layout_constraintEnd_toStartOf = "@ + ID/rightView"당신이 추가로'이동 응용하면 어떻게됩니까 'rightView'를 통해 'app : layout_constraintStart_toEndOf = "@ + id/leftView"'? – stkent@stkent 두 번째 경우와 거의 같은 동작입니다. 그러나이 경우'LayoutView '는'LayoutWidth'가'100dp'와 같은 어떤 값으로 설정되어 있지 않으면 화면의 전체 너비를 채 웁니다. 나는 그 행동을 이해하지 못한다. –