0

XML 파일에서 한 뷰 호출기의 layout_width (너비)을 다른 뷰어 호출기 (또는 시작 및 끝 정렬 모두 같음이어야 함)로 설정하려고합니다.ConstraintLayout - 뷰 페이지 호출기

다음 코드를 시도했지만 작동하지 않는 것 같습니다.

enter image description here

나는 오렌지보기 호출기와 같은 두 녹색보기 호출기의 폭을 원하는 : 여기

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.xxx.yyy.MainActivity"> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/vpTop" 
     android:layout_width="@+id/vpCenter" // Here trying to assign width equal to orange view 
     android:layout_height="40dp" 
     android:layout_marginBottom="20dp" 
     android:background="@android:color/holo_green_light" 
     app:layout_constraintBottom_toTopOf="@+id/vpCenter" 
     ></android.support.v4.view.ViewPager> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/vpCenter" 
     android:layout_width="200dp" 
     android:layout_height="200dp" 
     android:background="@android:color/holo_orange_light" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/vpBottom" 
     android:layout_width="@+id/vpCenter" // Here trying to assign width equal to orange view 
     android:layout_height="40dp" 
     android:layout_marginTop="20dp" 
     android:background="@android:color/holo_green_light" 
     app:layout_constraintTop_toBottomOf="@+id/vpCenter" 
     ></android.support.v4.view.ViewPager> 

</android.support.constraint.ConstraintLayout> 

는 미리보기입니다. 주 : 오렌지보기 호출기는 layout_width = 200으로 고정되어 있습니다. 두 개의 녹색보기 호출기에 고정 너비 (200)를 설정하고 싶지는 않지만 오렌지보기의 너비를 두 개의 녹색보기에 할당해야합니다.

enter image description here

어떻게 그것을 할 수 있습니다 : 나는 이런 식으로 뭔가를 원하는

(시작과 끝 정렬은 동등해야한다)? 당신이 싶어 나는 뭔가를했다

답변

1

은이 :이 XML의

<?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"> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/vpTop" 
     android:layout_width="0dp" 
     android:layout_height="40dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginTop="8dp" 
     android:background="@android:color/holo_green_light" 
     app:layout_constraintBottom_toTopOf="@+id/vpCenter" 
     app:layout_constraintEnd_toEndOf="@id/vpCenter" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintStart_toStartOf="@+id/vpCenter" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintVertical_bias="1.0" /> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/vpCenter" 
     android:layout_width="200dp" 
     android:layout_height="200dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginStart="8dp" 
     android:layout_marginTop="8dp" 
     android:background="@android:color/holo_orange_light" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/vpBottom" 
     android:layout_width="0dp" 
     android:layout_height="40dp" 
     android:layout_marginTop="8dp" 
     android:background="@android:color/holo_green_light" 
     app:layout_constraintEnd_toEndOf="@+id/vpCenter" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintStart_toStartOf="@+id/vpCenter" <!--key attributes--> 
     app:layout_constraintTop_toBottomOf="@+id/vpCenter" /> 

</android.support.constraint.ConstraintLayout> 


출력은 다음과 같습니다
output

+0

니스, 작동 중입니다. – Krunal

+0

도와 드리겠습니다. 좋은 하루 되세요! –

1

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.xxx.yyy.MainActivity"> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/vpTop" 
     android:layout_width="0dp" 
     android:layout_height="40dp" 
     android:layout_marginBottom="10dp" 
     android:background="@android:color/holo_green_light" 
     app:layout_constraintBottom_toTopOf="@+id/vpCenter" 
     app:layout_constraintEnd_toEndOf="@id/vpCenter" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintStart_toStartOf="@+id/vpCenter" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintVertical_bias="1.0" /> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/vpCenter" 
     android:layout_width="200dp" 
     android:layout_height="200dp" 
     android:background="@android:color/holo_orange_light" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/vpBottom" 
     android:layout_width="0dp" 
     android:layout_height="40dp" 
     android:layout_marginTop="10dp" 
     android:background="@android:color/holo_green_light" 
     app:layout_constraintEnd_toEndOf="@+id/vpCenter" 
     app:layout_constraintStart_toStartOf="@+id/vpCenter" 
     app:layout_constraintTop_toBottomOf="@+id/vpCenter" /> 


</android.support.constraint.ConstraintLayout> 

OUTPUT을 시도

enter image description here

+1

노력해 주셔서 감사합니다 :) – Krunal

+0

@Krunal이 도와 드리겠습니다. –