2017-06-21 3 views
4

ConstraintLayoutに鎖を含むビューのグループを合わせます垂直鎖、およびはチェーンに対して中心に配置されています。しかし、グループ全体を親の中心に揃えるにはどうすればいいですか? のCは、GONEであることに注意してください。私はConstraintLayoutで3つのビューがあり、このように、その後整列する

<android.support.constraint.ConstraintLayout 
    android:id="@+id/outerLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.constraint.ConstraintLayout 
     android:id="@+id/innerLayout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent"> 

     [A, B, and C views here...] 

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

外側のレイアウトができます。

答えて

0

グループを中心にする最も簡単で理解しやすい方法は、次のようにConstraintLayoutにネストされ、ConstraintLayout、自身内のビューを入れ子にすることで、それをグループにすることです他のタイプのViewGroup、例えば、LinearLayoutgravityを使用してもよい。

チェーン、障壁、ガイドラインなどの創造的な使用など、他の解決策も可能ですが、その概要が簡単です。

2

レイアウトを入れ子にしない視覚的な答えです。

animated demonstration

ステップ

  1. Chain and pack B及びC垂直
  2. チェーンパックA及びC水平
  3. 合わせB及びCの水平中心
  4. センター垂直
+0

ビューCが 'GONE'の場合は、BとCを' LinearLayout'でラップし、残りのレイアウトを制約で行うのが最も簡単だと思います。これは、BがCよりも広い潜在的な問題も解決するだろう。 – Suragch

関連する問題