2012-12-25 39 views
1

我是Android新手,使用Relative Layout。現在我試圖更改控件的ID,但只要我更改ID,其他控件就會重新定位,因爲它們是相對於彼此的。他們有沒有辦法改變控件的ID而不重新定位它們?如何在相對佈局中修改控件的ID?

回答

0

因爲相對佈局中的每個對象都是基於對象ID排列的。一旦你改變了一個對象ID,你也需要在另一側改變它的對象ID。如果不是這樣,佈局會很糟糕,需要重新排列。

避免這種情況的最好方法是在繼續之前聲明每個對象ID。

我的建議是你一個一個地改變了對象ID。將對象ID的所有字段更改爲最新。

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignRight="@+id/textView2" 
    android:layout_below="@+id/login_email" 
    android:layout_marginTop="46dp" 
    android:text="@string/password_text" /> 


<EditText 
    android:id="@+id/login_password" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/textView3" 
    android:layout_alignBottom="@+id/textView3" 
    android:layout_alignRight="@+id/login_email" 
    android:layout_toRightOf="@+id/textView3" 
    android:ems="10" 
    android:password="true" 
    android:singleLine="true" /> 

<Button 
    android:id="@+id/register_button" 
    android:layout_width="100dip" 
    android:layout_height="40dip" 
    android:layout_alignRight="@+id/login_password" 
    android:layout_below="@+id/login_password" 
    android:text="@string/signup_text" /> 

例如,基於上面的代碼,一旦更改TextView ID從@+id/textView3@+id/password_text。您需要在包含@+id/textView3@+id/password_text的對象中逐個更改。這是在

<EditText 
    android:layout_alignBaseline="@+id/textView3" 
    android:layout_alignBottom="@+id/textView3" 

順便嘗試在你的問題標籤Android。更多的人會這樣注意你的問題。

+0

非常感謝... – SiD