我有一个TextView在我的应用程序。我想让文本向右对齐。我试着补充道:

android:gravity="right"

但这对我没用。

我可能做错了什么?


当前回答

layout_gravity用于将文本视图与父布局对齐。 Android:gravity用于在文本视图中对齐文本。

你确定你是在试图将文本视图中的文本向右对齐还是你想要将文本视图本身相对于父布局向右移动,还是你想同时实现这两种目的

其他回答

你可以使用:

    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"

以下代码片段:

android:textAlignment="textEnd"
android:layout_gravity="end"

对我来说很好

试着使用:-

android:justificationMode="inter_word"

这将证明你的短信是正确的。

确保你没有使用android:layout_width="wrap_content"如果是这样,那么它将无法设置重力,因为你没有足够的空间来对齐文本。而是使用android:layout_width="fill_parent"

我也面临同样的问题,并认为问题正在发生,因为TextView的layout_width是有wrap_content。你需要有layout_width为match_parent和android:gravity = "gravity"