2011-05-22 109 views
4

這是我目前的ListView項目佈局:的RelativeLayout的TextView覆蓋

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:paddingTop="6dp" 
android:paddingRight="6dp" 
android:paddingBottom="6dp"> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingLeft="6dp"> 

    <TextView 
     android:id="@+id/departure_line" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:singleLine="true" 
     android:textSize="16sp" 
     android:textStyle="bold" 
     android:shadowColor="#000000" 
     android:shadowDx="1" 
     android:shadowDy="1" 
     android:shadowRadius="1" 
     android:paddingLeft="3dp" 
     android:paddingRight="3dp" /> 
</RelativeLayout> 

<TextView 
    android:id="@+id/departure_destination" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_marginLeft="52dp" 
    android:background="#777777" 
    android:singleLine="true" 
    android:ellipsize="end" 
    android:textSize="16sp" /> 
<TextView 
    android:id="@+id/departure_time" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_alignParentRight="true" 
    android:textSize="16sp" /> 
</RelativeLayout> 

我的問題是目標的TextView覆蓋的時間TextView的,你可以在屏幕上看到。如何防止呢?

http://www.abload.de/image.php?img=screensk6y.png

回答

1

使用Android:layout_toLeftOf = 「@ + ID/DEPARTURE_TIME」 在您的目的地,或者你可以在一個TableLayout>

+0

要做到這一點的唯一方法是使用TableLayout,因爲RelativeLayout總是在佈局安排中覆蓋TextView。 – CannyDuck 2011-06-03 22:04:49

+0

事實上,只要你使用佈局定義textView的邊緣,它就會隨時隨地走到你想要的位置,高度/寬度將停止在你告訴它的位置 – KyleM 2012-05-09 01:40:09

+0

謝謝你的回答!對於在問題中包含工作「覆蓋」的問題提問者做得很好。這使得找到解決方案變得非常容易。 – 2012-06-20 16:44:40

1

使用屬性: 機器人:layout_below = 「@ /標記」

您可以在一個RelativeLayout的做到這一點。並從你的RelativeLayout中刪除方向屬性,這是沒用的。

你可以做到以下幾點:

  • 使用的LinearLayout,你有屬性的方向。
  • 使用的RelativeLayout,展望layout_below屬性
+0

請糾正我,如果我做錯事。在我的時間視圖中添加了一個「android:layout_below =」@ + id/departure_destination「」,但現在時間內容被包裝到一個新行中。那不是我想要的。目標不應該覆蓋時間視圖,它們應該在之前結束,它們的文本應該被截斷並填充點。 – CannyDuck 2011-05-22 10:14:37

+0

我明白你錯了。所以layout_below屬性不能解決你的問題。嘗試ALIGN_RIGHT屬性=「departure_time」。 – tobias 2011-05-25 21:01:06

1
android:ellipsize="end" 

設置它們均上漲如果時間太長,這會將文本截斷。或者你可以做

android:ellipsize="marquee" 

它會像安卓市場中的應用程序名稱一樣滾動。有時你不得不放棄

android:singleLine="true" 

在那裏爲它工作,還我會建議

android:marqueeRepeatLimit="marquee_forever" 

以便它繼續的情況下,移動用戶錯過了它的第一次。

所看到的Layout TricksTextView ellipsize