2016-07-13 13 views
0

EditTextの右側にCheckBoxを揃えようとしています。問題は私が自分のやり方で行うならば、私は循環依存性があることです。AlignBaseLineしかし、Androidのレイアウトで循環依存を避ける

私は、EditTextのベースラインにPowerboxとLandlineのチェックボックスを合わせたいと思います。

screenshot

は現在、私はあなたが、私は彼らが底にもう少しことにするチェックボックスで

android:paddingTop="5dp" 

を使用見ることができるように、このコード

 <CheckBox 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/txt_elec_box" 
      android:id="@+id/electricityBox" 
      android:layout_below="@id/streetText" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:paddingTop="5dp" /> 

     <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"     
      android:id="@+id/streetNumText" 
      android:layout_below="@id/streetText" 
      android:layout_alignStart="@id/electricityBox" 
      android:layout_alignLeft="@id/electricityBox" 
      android:layout_alignParentStart="true" 
      android:layout_alignParentLeft="true" 
      android:hint="@string/txt_street_check" 
      android:layout_toLeftOf="@id/electricityBox" /> 

     .... 

     <CheckBox 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/txt_landline" 
      android:id="@+id/landlineBox" 
      android:layout_below="@id/familyNameText" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true"     
      android:paddingTop="5dp" /> 

     <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"     
      android:id="@+id/phoneNumberText" 
      android:layout_below="@id/familyNameText" 
      android:layout_alignStart="@id/landlineBox" 
      android:layout_alignLeft="@id/landlineBox" 
      android:layout_alignParentStart="true" 
      android:layout_alignParentLeft="true" 
      android:layout_toLeftOf="@id/landlineBox" /> 

を使用しますが、私が欲しいですしたいですか?

android:layout_alignBaseline="@id/phoneNumberText" 

ですが、循環依存性が発生します。

これはハードコードされていない幅の方法で可能な場合でもチェックボックスを水平に揃えたい(スクリーンショットの完璧な位置合わせは私のアプリの英語バージョンを使用している)。

+0

あなたは順序を逆にしてはい 'landlineBox'' toRightOf' 'phoneNumberText' –

+0

を置くが、表示サイズが十分に大きくないならば、チェックボックスのテキストが2行に分割されることができます。私は、できるだけ多くのスペースを取るEditTextが必要ですが、チェックボックス以上のものは必要ありません –

答えて

1

まず、RelativeLayout行い、その後、あなたのレイアウトの各行の項目について、あなたの親のレイアウトはのLinearLayoutことにします。このような何か:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/streetText"> 

    <EditText 
     android:id="@+id/streetNumText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_toLeftOf="@id/electricityBox" 
     android:hint="@string/txt_street_check" /> 

    <CheckBox 
     android:id="@+id/electricityBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:text="@string/txt_elec_box" /> 

</RelativeLayout> 
+0

それは動作します。垂直方向の位置合わせはまだありますが、それは別の話ですね。ありがとう。 –

0

のLinearLayoutでそれらをラップし、重力(またはlayout_gravity)を使用する=「センター」

+0

私のために働いていません。私はEditTextの左揃えをしたい。また、チェックボックスのテキストが途切れてしまいます。 –