2013-05-14 2 views
4

동일한 '행'에 두 개의보기가 있고 너비가 "fill_parent"인 Android의 경우보기 크기는 어떻게 계산됩니까?layout_width = "match_parent"인 Android RelativeLayout 및 하위

예 :

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"> 
    <EditText 
     android:id="@+id/EditText01" 
     android:hint="Enter some text..." 
     android:layout_alignParentLeft="true" 
     android:layout_width="match_parent" 
     android:layout_toLeftOf="@+id/Button01" 
     android:layout_height="wrap_content"></EditText> 
    <Button 
     android:id="@+id/Button01" 
     android:text="Press Here!" 
     android:layout_width="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_height="wrap_content"></Button> 
</RelativeLayout> 

이 코드는 글고 모든 여유 공간을 제공하고 자신의 오른쪽에있는 버튼을 보여줍니다. 이것은 글고 모든 폭을 채우고 변경하고 버튼을 화면 벗어나으로하지만 다음 Button 왼쪽에 정렬하는 EditText의 경계 오른쪽 강제

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"> 
    <EditText 
     android:id="@+id/EditText01" 
     android:hint="Enter some text..." 
     android:layout_alignParentLeft="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"></EditText> 
    <Button 
     android:id="@+id/Button01" 
     android:text="Press Here!" 
     android:layout_width="wrap_content" 
    android:layout_toRightOf="@+id/EditText01" 
     android:layout_height="wrap_content"></Button> 
</RelativeLayout 

답변

7

android:layout_toLeftOf="@+id/Button01", 따라서 안드로이드는 match_parent 폭을 무시 너비는 버튼의 왼쪽 부모 측에서 오른쪽으로 만 채 웁니다.

android:layout_toRightOf="@+id/EditText01"EditText의 오른쪽으로 정렬 할 Button의 경계 왼쪽 강제되지만 EditText이므로 match_parent 폭 권리 측 부모 뷰의 오른쪽으로 정렬 안드로이드 단지 버튼을 강제 화면에서.

+0

덕분에, 지금은 이해합니다. 나는 너를 투표 할 수 없다 : ( – juan

+0

미래에 너는 되돌아 올 수 있었다 :) 그리고 너는 환영 받는다 – TronicZomB

1

두 예 모두에서 <EditText/>은 화면의 너비에 맞습니다. 첫 번째 예에서 Button<EditText/>에 종속되지 않으므로 화면의 오른쪽 가장자리에 맞출 수 있습니다. 그러나 두 번째 예에서는 Button이`의 오른쪽에 정렬되어야합니다. 그래서 그것이 보이지 않게 밀려납니다.

+0

고마워, 지금 나는 이해한다. 투표 할 수 없습니다. ( – juan

0

RelativeLayout을 사용하는 경우 "행"이 없다면보기를 정렬 할 수있는 공간 만 있으면됩니다. 화면의 오른쪽에있는 버튼을 계속 원하고있는 경우 글고 당신이 이런 식으로 뭔가를 할 수있는 화면의 나머지를 채우

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"> 
    <EditText 
     android:id="@+id/EditText01" 
     android:hint="Enter some text..." 
     android:layout_toLeftOf="@+id/Button01" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"></EditText> 
    <Button 
     android:id="@+id/Button01" 
     android:text="Press Here!" 
     android:alignParentRight="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"></Button> 
</RelativeLayout/> 
+0

예, RelativeLayout에 행이 없다는 것을 알고 있는데, 이것이 인용 부호의 이유였습니다. 구체적인 해결책이 아닌 match_parent가 어떻게 작동하는지 알고 싶었습니다. 감사합니다. – juan