2013-05-10 184 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"