Android TextView 右对齐

标签 android css android-layout android-listview

<TextView
    android:id="@+id/postedBy"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/content"
    android:layout_marginTop="5dp"
    android:text="@string/postedBy"
    android:textColor="#000000"
    android:textSize="12sp" />

<TextView
    android:id="@+id/username"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@id/content"
    android:layout_marginTop="5dp"
    android:textColor="#00aadd"
    android:textSize="12sp" />

我正在尝试在应正确对齐的新闻文章下创建“按姓名发布”。此时用户名在它应该在的地方,但我无法在它的左边找到另一个 TextView 。注意:layout_toLeftOf="@id/username"不起作用。

有人能帮我吗?

提前致谢。

最佳答案

layout_toLeftOf 应该在 RelativeLayout 中工作:

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

<TextView
    android:id="@+id/postedBy"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/content"
    android:layout_marginTop="5dp"
    android:text="@string/postedBy"
    android:textColor="#000000"
    android:textSize="12sp" 
android:layout_toLeftOf="@+id/username"
    />

<TextView
    android:id="@+id/username"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@id/content"
    android:layout_marginTop="5dp"
    android:textColor="#00aadd"
    android:textSize="12sp" 
    />
</RelativeLayout>

关于Android TextView 右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20020685/

相关文章:

android - 构造函数 GeoPoint(double, double) 未定义。这有什么问题吗?

android - 创建自定义 ListView 布局,就像在 Play 商店应用中一样

css - 使用 CSS 定位背景图片

html 在div中间放一张图片

jquery - 如何在 colorbox 或 fancybox 中添加菜单(导航)

android - 如何使用加速度计值刷新网页

java - FLAG_ACTIVITY_NEW_TASK不打开以前的 Activity ,而仅在新安装apk时打开

android - 我在哪里可以找到 Android Studio 2.2 Preview 1 中的新布局检查器

java - ListView 未正确填充/不可见

android - 你如何创建一个只允许水平方向的应用程序?