如何在安卓系统中对齐文本

15

我想在安卓中将文本对齐到左下角。


你目前对 XML 的看法是什么? - jball
你有什么代码?你现在使用的 XML 是什么样子的? - wheaties
3个回答

39
如果你想将TextView中的文本对齐到左下角,请使用android:gravity="bottom|left"。如果你想将TextView对齐到其容器的左下角,请使用android:layout_gravity="bottom|left"。不过,我怀疑你没有准确表达你的真实意图。你想将一些文本对齐到什么位置的左下角呢?屏幕的左下角吗?还是文本容器的左下角?请尽量明确你的问题。如果是要对齐到屏幕的左下角:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="bottom|left"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="text"/>
</FrameLayout>

屏幕左下角 - ryan
我不会为此目的使用框架布局。请改用相对布局。 - Janusz

3
我建议使用相对布局
你的视图将如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text aligned bottom left"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>

1

android:layout_alignParentBottom="true" android:layout_alignParentLeft="true"

必须写在TextView中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接