gpt4 book ai didi

android - 无法在 TableRow 中动态居中 TextView

转载 作者:行者123 更新时间:2023-11-29 00:47:19 26 4
gpt4 key购买 nike

我动态创建了一个带有 ImageButton 和 TextView 的 TableRow。我使用 TableRow.setGravity(Gravity.CENTER_VERTICAL);

在我的 TableRow 上设置了引力

然后,在我的 TextView 上,我正在使用这段代码

TextView tv = new TextView(this);
tv.setText(functie[beschrijving]);
tv.setWidth(300);
//tv.setHeight(60);
tv.setGravity(Gravity.CENTER_VERTICAL);
tv.setPadding(15, 0, 10, 0);
tr.addView(tv);

当我这样做时,我得到了这个结果。它不是很居中,它看起来像中心正下方的文本。有谁知道如何将文字完全居中?

enter image description here

最佳答案

嗨我认为你应该使用父布局的以下属性android:layout_centerVertical="true"

关于android - 无法在 TableRow 中动态居中 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5700217/

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