对齐文本(即使其适合文本视图并覆盖所有空间)

时间:2018-07-01 19:21:53

标签: android android-layout layout textview

我正在尝试制作一个涉及用阿拉伯语写一些诗的应用程序,但是我很难使这首诗看起来合理,以便在阅读时显得美观。

我正在使用TableLayout填写这首诗:

<TableLayout
        android:id="@+id/whole_line_table"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center_vertical"
        android:stretchColumns="1"
        >
        <TableRow
            android:padding="6dp">
            <TextView
                android:layout_width="0dp"
                android:id="@+id/poem2_textView"
                android:layout_weight="1"
                android:gravity="right"
                android:textSize="15sp"
                tools:text="Some text here"
                />

            <TextView
                android:id="@+id/poem1_textView"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:gravity="right"
                android:textSize="15sp"
                tools:text="Some text here"
                android:maxLines="1"/>
        </TableRow>
    </TableLayout>

我希望这首诗出现在下图中的示例

verse example

您可以看到诗歌中的每一节经文如何开始和结束,并注意它们之间的间隔。

到目前为止我在布局中拥有的屏幕截图如下所示 enter image description here

我希望右侧部分延伸到不止textView的一半。

我对开发应用程序是完全陌生的,请原谅我任何不好的编码外观

1 个答案:

答案 0 :(得分:0)

设置文本宽度以填充父级,并为元素设置边距。 使用重心。

       <TextView
        android:id="@+id/poem1_textView"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:textSize="15sp"
        android:margin="18dp"    
        tools:text="Some text here"
        />

这可以帮助您模拟对齐的文本,如果您想要更好的修复程序,或者您正在使用android 8.0。它支持文本对齐。 查看此答案,然后尝试使用那些库。 Android TextView Justify Text

我希望能帮上忙。