使用TextView底部对齐,换行位于顶部。

huangapple go评论68阅读模式
英文:

With TextView alignment bottom, line breaks are at the top

问题

我的应用程序中,我希望将文本对齐到右下角。<br/>
目前看起来不错。<br/>
但是,我希望我的换行符遵守给定的重力,以便较长的文本位于底部。

示例:

> Lorem ipsum dolor sit amet, consectetur adipiscing<br/>
> elit. Cras sollicitudin

应该更像是:

> Lorem ipsum dolor <br/>
> sit amet, consectetur adipiscing elit. Cras sollicitudin

我的TextView看起来像这样:

```xml
<TextView
    android:id="@+id/text_bottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAlignment="textEnd"
    android:gravity="bottom|end"
    android:layout_alignParentBottom="true"/>

我期望android:gravity="bottom|end"会给我想要的结果,但据我所知,它似乎没有改变任何内容。


<details>
<summary>英文:</summary>

*A similar question has been asked [here](https://stackoverflow.com/questions/48130545/bottom-aligned-text-line-break-upwards), though not for Android development and it hasn&#39;t been answered in a sufficient way.*

In my app I want to align text to the bottom right.&lt;br/&gt;
So far so good.&lt;br/&gt;
However, I want my line breaks to respect the given gravity, so that the longer text is at the bottom.

Example:

&gt; Lorem ipsum dolor sit amet, consectetur adipiscing&lt;br/&gt;
&gt; elit. Cras sollicitudin

should look more like

&gt; Lorem ipsum dolor &lt;br/&gt;
&gt; sit amet, consectetur adipiscing elit. Cras sollicitudin

My `TextView` looks like this:

<TextView
android:id="@+id/text_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="textEnd"
android:gravity="bottom|end"
android:layout_alignParentBottom="true"/>


I expected `android:gravity=&quot;bottom|end&quot;` to give me the desired result but as far as I can tell it didn&#39;t change anything.

</details>


# 答案1
**得分**: 1

这仅仅通过TextView属性是不可能的。您应该编写自己的TextView来修改行为。

<details>
<summary>英文:</summary>

That&#39;s not possible only with TextView attributes. You should write your own TextView to modify the behavior.

</details>



huangapple
  • 本文由 发表于 2023年5月15日 12:37:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76250914.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定