버튼과 EditText가 같은 높이 (화면의 아래쪽)에 정렬되고 화면 너비를 공유한다고 가정 해 보겠습니다. 버튼에 필요한 공간 만 남기고 editText는 나머지 너비를 덮고 싶습니다.상대 레이아웃에서 요소간에 화면의 너비를 나눕니까?
지금까지 linearLayout을 사용했습니다.이 경우 두 요소를 수평 선형 레이아웃 안에 넣을 수 있으며 editText의 무게를 1로 설정하고 버튼의 끝을 wrap_content로 설정하면 작동 할 것이다.
그러나 상대 레이아웃을 사용하여이 동작을 복제 할 수 없습니다. 부모의 맨 아래에 editText를 놓고 버튼을 오른쪽으로 설정할 수 있지만 editText가 버튼의 공간을 존중하는 나머지 너비를 채우는 방법을 모르겠습니다.
올바른 방법은 무엇입니까?
편집 :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:hint="@string/editText_Hint"
android:inputType="number" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="@id/edittext"
android:onClick="sendAnswer"
android:text="@string/button_text" />
</RelativeLayout>
그리고 나는이의 행동을 복제 할 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
/*other stuff here*/
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/edittext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/editText_Hint"
android:inputType="number"
android:layout_weight="1"
/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_text"
android:onClick="sendAnswer"/>
</LinearLayout>
</LinearLayout>
귀하의 XML 코드 –
@Dilavar 편집을 넣어주세요 코드가 포함되었습니다. – kace91
첫 번째 (XML에서) 너비로 내용을 부모의 아래쪽 및 오른쪽으로 줄입니다 (정렬). 다음 편집 왼쪽 하단 부모 (정렬) 및 단추 너비의 오른쪽 0dp – Selvin