2014-09-05 165 views
0

我有以下布局。当我在Eclipse的图形布局视图中查看它时,它看起来很好。但是在电话上时,这并未反映出来。相对布局在Eclipse中看起来不错,但不在设备上

在电话上,TextView rowlogmessage占据了整个视野,其他TextView被压在了底部。

任何想法为什么?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/rounded_corners_white" > 

    <TextView 
     android:id="@+id/rowlogmessage" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="log message goes here" 
     android:textColor="#707070" 
     android:layout_alignParentTop="true" /> 

    <TextView 
     android:id="@+id/rowlogcreatedat" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="log message created at" 
     android:textColor="#707070" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" /> 

    <TextView 
     android:id="@+id/rowlogcreatedatlabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Created at" 
     android:layout_alignParentLeft="true" 
     android:layout_above="@id/rowlogcreatedat" 
     android:paddingTop="10dp" /> 

    <TextView 
     android:id="@+id/rowlogsentserver" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="log message sent to server" 
     android:textColor="#707070" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" /> 

    <TextView 
     android:id="@+id/rowlogsentserverlabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Sent to server" 
     android:layout_alignParentRight="true" 
     android:layout_above="@id/rowlogsentserver" 
     android:paddingTop="10dp"/> 

</RelativeLayout> 

回答

1

是的。在所有其他TextView之后(使用相对性属性将它放置在它必须放置的位置之上,rowlogcreatedat,并将其与父级顶部对齐 - 如现在一样)放置“我正在采用剩余的空间”。

另请注意,由于包含API级别8,因此不推荐使用fill_parent
改为使用match_parent

还要注意,正确的Java命名使用camelCaseNamingConvention,第一个字母是小写字母。

+0

谢谢,工作正常 – turtleboy 2014-09-05 09:57:58

+0

很高兴知道这一点。我也使用这种技术。 ;) – 2014-09-05 10:10:06

+0

用于命名约定。这不是java它是XML。 – 2016-03-13 22:03:04

-1

我建议您将宽度从fill_parent更改为wrap_content

而且在eclipse中将设备视图更改为关闭手机。默认情况下,eclipse使用nexus 5布局的“5英寸”屏幕。

0

试试这个,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/holo_blue_light" 
    android:orientation="vertical" 
    android:padding="5dp" > 

    <TextView 
     android:id="@+id/rowlogmessage" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="log message goes here" 
     android:textColor="#707070" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/rowlogcreatedat" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="left" 
      android:text="log message created at" 
      android:textColor="#707070" /> 

     <TextView 
      android:id="@+id/rowlogcreatedatlabel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="right" 
      android:text="Created at" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/rowlogsentserver" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="left" 
      android:text="log message sent to server" 
      android:textColor="#707070" /> 

     <TextView 
      android:id="@+id/rowlogsentserverlabel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="right" 
      android:text="Sent to server" /> 
    </LinearLayout> 

</LinearLayout> 
0

您在rowlogcreatedat这就是为什么它对准screen.Your其他TestView的底部引用此rowlogmessage TextView或使用android:layout_alignParentBottom="true"其相关TextView所以他们也attcached沿与屏幕的底部你的rowlogcreatedat TextView。 删除android:layout_alignParentBottom="true"然后看它如何排列在屏幕上。也可以使用match_parent而不是wrap_content

相关问题