2013-05-10 182 views
0

我是android新手,我有一個關於relativeLayout的問題,相對Lyout中的所有視圖都沒有顯示:editTexts和spinners,我看不到錯誤在哪裏: (Android RelativeLayout視圖不可見

這裏是XML文件:。

 <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.01" 
      android:orientation="horizontal" 
      android:padding="10dp" > 

      <EditText 
       android:id="@+id/fname" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1.0" 
       android:hint="@string/fname" 
       android:inputType="text" 
       android:textSize="12sp" 
       /> 

      <EditText 
       android:id="@+id/lname" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1.0" 
       android:hint="@string/lname" 
       android:inputType="text" 
       android:textSize="12sp" 
       android:layout_toRightOf="@+id/fname" 

       /> 

      <Spinner 
       android:id="@+id/catspin" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:entries="@array/cat" 
       android:prompt="@string/cat" 
       android:layout_below="@+id/fname" 

       /> 

      <Spinner 
       android:id="@+id/rolespin" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:entries="@array/role" 
       android:prompt="@string/role" 
       android:layout_toRightOf="@+id/catspin" 

       /> 

      <EditText 
       android:id="@+id/oparea" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1.0" 
       android:hint="@string/oparea" 
       android:inputType="text" 
       android:textSize="12sp" 
       android:layout_below="@+id/catspin" 

       /> 

      <EditText 
       android:id="@+id/job" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1.0" 
       android:hint="@string/job" 
       android:inputType="text" 
       android:textSize="12sp" 
       android:layout_below="@+id/oparea" 

       /> 

      <EditText 
       android:id="@+id/phone" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1.0" 
       android:hint="@string/phone" 
       android:inputType="text" 
       android:textSize="12sp" 
       android:layout_below="@+id/job" 

       /> 

      <EditText 
       android:id="@+id/email" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1.0" 
       android:hint="@string/email" 
       android:inputType="text" 
       android:textSize="12sp" 
       android:layout_toRightOf="@+id/phone" 

       /> 



     </RelativeLayout> 
+2

你試過刪除'android:layout_weight'屬性嗎?你已經將它設置爲0.01的根目錄佈局。 – 2013-05-10 10:50:06

+0

謝謝,它現在的作品^^ – kyokotsu 2013-05-10 11:07:19

回答

0
<RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="10dp" 
      xmlns:android="http://schemas.android.com/apk/res/android"> 

      <EditText 
       android:id="@+id/fname" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:hint="@string/fname" 
       android:inputType="text" 
       android:textSize="12sp" 
       /> 

      <EditText 
       android:id="@+id/lname" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:hint="@string/lname" 
       android:inputType="text" 
       android:textSize="12sp" 
       android:layout_toRightOf="@+id/fname" 

       /> 

      <Spinner 
       android:id="@+id/catspin" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:entries="@array/cat" 
       android:prompt="@string/cat" 
       android:layout_below="@+id/fname" 

       /> 

      <Spinner 
       android:id="@+id/rolespin" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:entries="@array/role" 
       android:prompt="@string/role" 
       android:layout_toRightOf="@+id/catspin" 

       /> 

      <EditText 
       android:id="@+id/oparea" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1.0" 
       android:hint="@string/oparea" 
       android:inputType="text" 
       android:textSize="12sp" 
       android:layout_below="@+id/catspin" 

       /> 

      <EditText 
       android:id="@+id/job" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1.0" 
       android:hint="@string/job" 
       android:inputType="text" 
       android:textSize="12sp" 
       android:layout_below="@+id/oparea" 

       /> 

      <EditText 
       android:id="@+id/phone" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1.0" 
       android:hint="@string/phone" 
       android:inputType="text" 
       android:textSize="12sp" 
       android:layout_below="@+id/job" 

       /> 

      <EditText 
       android:id="@+id/email" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1.0" 
       android:hint="@string/email" 
       android:inputType="text" 
       android:textSize="12sp" 
       android:layout_toRightOf="@+id/phone" 

       /> 



     </RelativeLayout> 
4

layout_weightRelativeLayout不起作用,它是LinearLayout這麼你EditText S和Spinner s爲所有0dp寬,因此不可見

+0

謝謝它現在的作品 – kyokotsu 2013-05-10 11:08:43

-2

線性佈局,可以分配方向,但相對其佈局相互重疊,所以你需要做的ID爲每做出layout_below在每個觀點

0

RelativeLayout刪除android:layout_weight="0.01" android:orientation="horizontal"這兩個屬性,然後檢查。

android:layout_weightRelativeLayout中不起作用,它的作用是LinearLayout。因此,請製作您的EditTexts和Spinner的android:layout_width="wrap_content"