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

android:gravity="right"

但这对我没用。

我可能做错了什么?


当前回答

在我的例子中,我使用了属性“layout_alignRight”,在文本中:

android:layout_alignRight="@+id/myComponentId"

如果你想添加一些右边框,只需要设置属性“Layout_Margin right”为“20dp”,例如:

android:layout_marginRight="20dp"

其他回答

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

使(LinearLayout) android:layout_width="match_parent"和TextView的android:layout_gravity="right"

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

你可以使用:

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

试着使用:-

android:justificationMode="inter_word"

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