2016-10-07 16 views
0

私は、TextViewとEditTextの一番下を、RelativeLayoutの内側(ピクセルではないが近い)に配置しようとしています。しかしlayout_alignBottomではなく、その下の彼らの中心線をラインアップしているようだ:layout_alignBottomは、下端の代わりに中央を揃えます。

enter image description here

私もlayout_alignBaselineを試してみましたが、結果はのEditTextが画面に表示されないということでした。私は詰め物の調整にも様々な努力をしましたが、何も変わっていませんでした。これは簡単で共通の問題であるはずだが、私はグーグルでは何も見つけられなかったようだ。どんな助けでも大歓迎です。

ありがとうございました。

<TextView 
    android:id="@+id/firstNameLabel" 
    android:layout_marginTop="20dp" 
    android:layout_marginRight="24dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="First Name" /> 

<EditText 
    android:layout_toRightOf="@+id/firstNameLabel" 
    android:layout_alignBottom="@+id/firstNameLabel" 
    android:id="@+id/firstName" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    /> 

答えて

0

コードからマージントップを取り外し、これのEditTextがTextViewのよりも大きくされている原因は何

+0

ありがとうございましたが、2つの要素の互いの垂直方向の配置に違いはありませんでした。 –

0

をご確認ください。両方を含むレイアウトをチェックし、重力を「center」または「center_vertical」に設定します。

編集:あなたはRelativeLayoutを使用している場合は、おそらく代わりに

+0

私は、コンテナ内で垂直方向に要素の中心を合わせようとしていません。私はそれらを一番上に置き、互いに対して垂直に整列させようとします。 –

+0

ああ...おそらく別のレイアウトを利用することができます。 2つのビューを別のレイアウトにラップし、ビューを中心にして上に揃えます。 – jak10h

1

はこれを試してみてください "layout_centerVertical" または "layout_centerInParent" を使用する必要があります。

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <TextView 
     android:id="@+id/firstNameLabel" 
     android:layout_marginRight="24dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:text="First Name" 
     android:textSize="20sp"/> 

    <EditText 
     android:layout_toRightOf="@+id/firstNameLabel" 
     android:layout_alignParentBottom="true" 
     android:id="@+id/firstName" 
     android:hint="YO BABY" 
     android:layout_centerVertical="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 
</RelativeLayout> 

希望します。

+0

TextViewのためにandroid:layout_centerVertical = "true"を使用すると、テキストが正確に中央に配置されなくなるため、状況が改善されます。私は彼らを近づける方法があるかどうかまだ疑問に思っています。 RelativeLayoutでより正確に要素を垂直方向に並べることは、一般的なケースと思われます。 –

+0

あなたはボトムまたはセンターを揃えたいですか? – Harv

+0

底を揃えたいです。 –

関連する問題