4

同じ「行」に 2 つのビューがあり、1 つのビューが width="fill_parent" の場合、Android はビューのサイズをどのように計算しますか?

例:

<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>

このコードは、すべての空き領域を EditText に与え、ボタンを右側に表示します。しかし、この変更により、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
4

3 に答える 3

7

android:layout_toLeftOf="@+id/Button01"の右境界をEditTextの左側に揃えるように強制するButtonため、Android は幅を無視し、match_parent幅を強制的にボタンの左側の親側から右側にのみ埋めます。

android:layout_toRightOf="@+id/EditText01"の左境界をButtonの右側に揃えますが、EditTextEditTextmatch_parent広いため、右側は親ビューの右側に揃えられ、Android はボタンを画面から強制的に外します。

于 2013-05-14T14:21:52.177 に答える