android - 无法在布局中将文本右对齐

标签 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

(布局是 ListView 中的一行)

最佳答案

预览显示您的布局,但没有信息将在何处膨胀,假定为“全屏”布局。但是您的 XML 代码是容器 (ListView) 中的一部分,它可能已将 layout_width 设置为 wrap_content(或固定值)。你的 ListView 应该有 match_parent (也许还有它的父级)。显示更多代码,尤其是 ActivityFragment(如果您正在使用)。

关于android - 无法在布局中将文本右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40774875/

相关文章:

layout - libgdx 表仅在右下区域布置组件

ios - Xcode 10 - iOS 9.0 之前的 Safe Area Layout Guide [12] 错误

android - Jetpack 根据大小组成具有自适应列数的网格

java - Android SpeechRecognizer设置识别引擎?

android-layout - 贺卡翻页动画

python - 从seaborn散点图中的点中删除白色边框

css - 关于布局提交按钮的问题

android 7 中的 android、相机和裁剪图像

android - 使用OpenGL-ES(android)画线的最简单方法是什么

android - android中的动态相对布局