gpt4 book ai didi

android - 将布局中的文本居中,用另一个 View 限制左侧大小

转载 作者:行者123 更新时间:2023-11-30 04:11:44 25 4
gpt4 key购买 nike

让我解释一下,需要根据父级将 tex 居中,但要考虑到布局左侧的 View :

|------------Screen--------------|
[View] [Short Text]

|------------Screen--------------|
[View][Loooooooooooooooooong Text]

使用相对布局重力属性我只得到这个:

|------------Screen--------------|
[View] [Short Text] <------THIS IS WRONG.

|------------Screen--------------|
[View][Loooooooooooooooooong Text]

提前致谢

问题是如何进行布局。没有代码可以开始它无论如何都可以完成(当然不使用固定值的 View 宽度),我实际上是用相对的,但没有运气。

现在如果你真的想要从头开始的东西,现在我正在使用@Padma Kumar 的建议

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_weight="0"
android:src="@drawable/something" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>

最佳答案

将您的 2 个 View 置于线性布局中

//使用android:layout_Weight

对于您的观点,权重为“0”对于您的短 TextView ,将权重设置为“1”,将重力设置为左侧。

这会很好用

关于android - 将布局中的文本居中,用另一个 View 限制左侧大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10761349/

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