2014-09-05 82 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

相關問題