2012-03-12 2 views
1

EditText를 버튼없이 수평으로 정렬하려고합니다. 둘 다 같은 높이가되어야하며 꼭대기와 밑면은 서로 정렬되어야합니다. 내 코드는 다음과 같습니다.EditText를 버튼으로 맞추기

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <EditText 
     android:id="@+id/quantity" 
     android:inputType="number" 
     android:layout_height="fill_parent" 
     android:layout_width="100dp" 
     android:layout_toRightOf="@id/quantity_label" 
     android:background="@android:drawable/editbox_background" /> 
    <Button 
     android:onClick="submitButtonTapped" 
     android:id="@+id/submit" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_toRightOf="@id/quantity" 
     android:drawableLeft="@drawable/submit_icon" 
     android:drawablePadding="5dp" 
     android:text="@string/submit" /> 
</LinearLayout> 

결과적으로 두 요소의 아래쪽이 정렬됩니다. EditText의 포커스 테두리는 Button 아래로 확장됩니다. EditText는 포커스 테두리가있는 경우에도 Button의 높이까지 확장되지 않습니다. 어떻게 정렬합니까?

+0

문제는 android : background = "@ android : drawable/editbox_background"- 예상대로 작동하지 않음 –

+0

해당 줄이 없으면 문제가 반전됩니다 : 상단이 정렬되고 EditText의 하단 버튼 하단에 도달하지 않습니다. – jcm

답변

1
  1. dimen/line_height 값으로 설정하십시오.
  2. 사용이 레이아웃
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="@dimen/line_height" 
android:orientation="horizontal" > 
<EditText 
    android:id="@+id/quantity" 
    android:inputType="number" 
    android:layout_height="fill_parent" 
    android:layout_width="100dp" 
    android:background="@android:drawable/editbox_background" /> 

<Button 
    android:id="@+id/submit" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:drawableLeft="@drawable/submit_icon" 
    android:onClick="submitButtonTapped" 
    android:text="@string/submit" /> 
</LinearLayout> 
+0

@ dimen/line_height 코드가 오류를 생성합니다. 지정된 이름과 일치하는 리소스가 없습니다 ('layout_height'값 '@ dimen/ line_height'). 감사. – jcm

+0

파일 입술/값/dimens.xml를 작성 ' 50dip ' –

+0

그것은, 하드 코딩있어 어느 나는 정말로 피하고 싶지만, 나는이 대답을 받아 들일 것이다. 감사. – jcm

0

은 또한 사용이

android:layout_marginTop="5dp" 

같은

가 대신있는 LinearLayout의 RelativeLayout의를 사용하여 버튼에 마진을 추가

andorid:layout_alignTop = "@id/quantity" 

희망이 작동합니다.

관련 문제