2012-10-12 26 views
0

當計時器開始計時時,'文本'有時正在移動..你認爲是什麼原因?我製作的天文臺裏面有一個相對的佈局,配上父母填滿..計時器位置不固定

有沒有其他的設置我錯過了?我還設置重力:記時計的中心

<RelativeLayout 
    android:id="@+id/relativeLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/textView1" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/textView1" 
    android:layout_marginBottom="10dp" > 

    <Chronometer 
     android:id="@+id/stopwatch" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:gravity="center_horizontal" 
     android:text="Chronometer" 
     android:textSize="110dp" /> 

</RelativeLayout> 

回答

-1

試試這個

<RelativeLayout 
    android:id="@+id/relativeLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/textView1" 
    android:layout_marginBottom="10dp" > 

    <Chronometer 
     android:id="@+id/stopwatch" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:gravity="center_horizontal" 
     android:text="Chronometer" 
     android:textSize="110sp" /> 
</RelativeLayout> 
+0

有什麼不同?指出它? – Adam91

+0

文本大小應該在SP中給出不在dp –

+0

不工作..試過.. – Adam91

0

android:gravity="center_horizontal"的問題。每次文本從增量刻度更改時,它會重新對齊水平居中的文本。如果您在天文臺中刪除中心路線,那麼您將不會遇到問題,因爲它應該默認爲左對齊。

您可能不得不使用邊距將天文臺放置在您需要的位置而不是佈局中。例如:

<Chronometer 
     android:id="@+id/stopwatch" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:text="Chronometer" 
     android:textSize="110dp" />