【问题标题】:RelativeLayout TextView overlay相对布局 TextView 覆盖
【发布时间】:2011-08-30 12:51:39
【问题描述】:

这是我当前的 ListView 项目布局:

<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

【问题讨论】:

    标签: android layout textview overlay android-relativelayout


    【解决方案1】:

    在您的目的地使用 android:layout_toLeftOf="@+id/departure_time" 或者您可以在 TableLayout 中同时设置它们>

    【讨论】:

    • 唯一的方法是使用 TableLayout,因为 RelativeLayout 总是在布局安排中覆盖 TextViews。
    • 实际上这不是真的,只要您使用布局定义 textView 的边缘,它就会几乎到达您想要的任何位置,并且高度/宽度将停止在您告诉它的位置
    • 感谢您的回答!对提问者做得很好,将工作“覆盖”包含在问题中。这使得找到解决方案变得非常容易。
    【解决方案2】:

    使用属性: android:layout_below="@id/label"

    您可以在一个相对布局中执行此操作。并从你的RelativeLayout中删除方向属性,它是没用的。

    您可以执行以下操作:

    • 使用LinearLayout,你就有了方向属性。
    • 使用 RelativeLayout 并查看 layout_below 属性

    【讨论】:

    • 如果我做错了什么,请纠正我。在我的时间视图中添加了“android:layout_below="@+id/departure_destination"”,但现在时间内容被换成了新行。那不是我想要的。目的地不应该覆盖时间视图,它们应该在之前结束,并且它们的文本应该被截断并用点填充。
    • 我理解错了。所以 layout_below 属性不能解决你的问题。试试 ALIGN_RIGHT 属性 = "departure_time"。
    【解决方案3】:
    android:ellipsize="end"
    

    如果文本太长,这将切断文本。或者你可以这样做

    android:ellipsize="marquee"
    

    它会像安卓市场中的应用名称一样滚动。有时你不得不扔

    android:singleLine="true"
    

    在那里工作,我也推荐

    android:marqueeRepeatLimit="marquee_forever"
    

    以便它继续移动以防用户第一次错过它。

    如Layout Tricks,TextView ellipsize中所见

    【讨论】:

      猜你喜欢
      • 2019-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-25
      相关资源
      最近更新 更多