2017-04-13 19 views
1

我有一個代表一個表單的活動佈局。該表格包含一些表單字段,包括一個微調器。將TextView與ConstraintLayout中的微調器正確對齊?

佈局的類型爲ConstraintLayout。

enter image description here

由於微調控件沒有一個基準,我不能垂直正確對齊我的「類」標籤。我在頂部使用24 dp作爲臨時數據。解決方案,但因爲微調將增加身高,我不喜歡這種解決方案。

是否有更好的解決方案讓Kind標籤正確對齊?

+0

why constraintlayout?你也可以使用相對或線性佈局。 – rafsanahmad007

+0

@ rafsanahmad007在性能方面,ConstraintLayout比其他人好得多。另外,無論佈局的複雜程度如何,它都可以讓您擁有平坦的層次結構。 –

+0

@ rafsanahmad007早在我曾經使用相對和線性佈局的日子裏,但我很高興我不必回去。 Constraintlayout使用起來非常簡單而且非常強大。 –

回答

5
<TextView android:id="@+id/video" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Lorem Ipsum" 
      app:layout_constraintBottom_toBottomOf="@+id/spinner" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="@+id/spinner" /> 

當錨定視圖到另一個的底部和頂部,將相對居中。這是垂直和水平有效的。
希望這會有所幫助。

+0

拇指向上!這個解決方案很好地工作。謝謝拉米 –

+0

好。請不要忘記檢查答案是否正確。 –

0

以我的經驗,TextView的且Spinner使用基線對齊(layout_constraintBaseline_toBaselineOf)對齊時更好。

<TextView 
     android:id="@+id/textview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Repeat"/> 

<Spinner 
     android:id="@+id/spinner" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:layout_constraintLeft_toRightOf="@id/textview" 
     app:layout_constraintBaseline_toBaselineOf="@id/textview" 
     android:layout_marginLeft="50dp"/> 
相關問題