无法在布局中将文本对齐到右侧

时间:2016-11-23 22:03:49

标签: android layout

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="70dp"
            android:layout_height="55dp"
            android:text="nope"
            android:id="@+id/cancel_arrive"
            android:onClick="selectNotGoing"
             />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:weightSum="1">

        <TextView
            android:id="@+id/attendingEventInListviewRow"
            android:layout_width="match_parent"
            android:layout_height="28dp"
            android:text="eventsName"
            android:height="30sp"
            android:textSize="22sp"
            android:gravity="right"
            android:tag="eventsName"
            />

        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="eventDayOfTheWeek"
        android:textColor="#000000"
        android:id="@+id/eventDayOfTheWeekTxt"
            android:gravity="right"

            />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="eventTime"
        android:textColor="#000000"
        android:id="@+id/eventTimeTxt"
        android:gravity="right"
        />

    </LinearLayout>


</LinearLayout>

我试图谷歌问题并实施我在这里找到的解决方案。什么都没有帮助。上面的代码是我当前的XML。我需要eventNameeventDayOfTheWeekeventTime才能保持在右侧。

我还尝试清理项目并重建它,但它保持不变。

(在预览中,文本位于右侧,启动后向左侧)

发布前(预览中):http://prntscr.com/db0ekp 发布后:http://prntscr.com/db0f7t

(布局是列表视图中的一行)

1 个答案:

答案 0 :(得分:1)

预览显示您的布局没有信息,它将被充气,假定为“wholescreen”布局。但是您的XML代码是容器内的一部分(ListView),可能已将layout_width设置为wrap_content(或固定值)。您的ListView应该match_parent(也可能是其父级)。显示更多代码,尤其是对于ActivityFragment,如果您正在使用。