2011-05-22 111 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