0

ビューページャのlayout_width(幅)をXMLファイルの別のページャ(または両方の開始位置と終了位置が等しいはずです)に等しく設定したいとします。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" 
    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> 

はプレビューです:

enter image description here

私はオレンジビューページャに等しいグリーンビューページャ両方の幅をしたいです。 注:オレンジビューページャは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はあなたを助けることを嬉しく思います –

関連する問題