【发布时间】:2014-09-24 16:13:07
【问题描述】:
我有一个ScrollView 的设置,其中包含一个TableLayout 和一些TableRows。
其中一个TableRows 有一个TextView 作为一个孩子。
所有元素都居中,包括TextView,但我想将文本视图中的文本左对齐。
如果 textview 不删除我的 \n 和 \t,我发现没有办法做到这一点。
android:textAlignment 也不起作用,我不想使用它,因为它需要最低 API 级别。
有没有一种方法可以在居中的文本视图中对齐文本?
一些代码
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_gravity="start">
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="430dp"
android:shrinkColumns="*"
android:stretchColumns="*"
android:layout_gravity="start"
>
<TableRow
android:id="@+id/tableRow_question_headline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dip" >
<TextView
android:id="@+id/quiz_question_headline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="4"
android:gravity="center"
android:layout_margin="10dip"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="@+id/tableRow_question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dip" >
<!-- The textview, which text should be left-aligned -->
<TextView
android:id="@+id/quiz_question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="4"
android:layout_margin="10dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
...
【问题讨论】:
-
从 TextView 中移除这一行 android:gravity="center"。
-
@Haresh 错误的文本视图,我在重要的文本视图上方添加了评论。它没有 android:gravity 行。
-
您的 TextView 文本包含 \t 或 \n ?
-
是的,确实可以,稍后缩进一些显示在那里的代码。
-
然后用空格简单替换。
标签: android textview text-alignment text-align