gpt4 book ai didi

android - 我怎样才能设置文本的位置?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:42:51 24 4
gpt4 key购买 nike

我有一个问题,我想将文本的位置设置为从特定位置开始。

例如:我的 TextView 中有此文本:abcd efgh ijkl mnop qrstu vwxyz

现在,我希望此文本从位置 efgh 而不是 abcd 显示如何在 textview 中执行此操作?我想更改文本的位置而不是 TextView 的位置。

谢谢

最佳答案

Nikki,只需像这样向您的 TextView 添加一个 marginLeft 属性:

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="Testing"
/>

您只需用您想要的任何值替换左边距。

编辑:对于代码,您应该能够使用以下内容:

TextView tv = new TextView(this);
LayoutParams lp = new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
lp.setMargins(left, top, right, bottom); //use ints here
tv.setLayoutParams(lp);

只是为了它的 hell ,这里是如何在一行中完成:)

TextView tv = new TextView(this).setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT).setMargins(left, top, right, bottom));

关于android - 我怎样才能设置文本的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4373334/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com