gpt4 book ai didi

android - 按钮文本显示为垂直

转载 作者:行者123 更新时间:2023-11-29 02:16:19 25 4
gpt4 key购买 nike

我的项目运行良好,突然按钮上的文本垂直显示。我的意思是不显示 map_infobutton

Info

正在显示

I
n

即使我在包含按钮的 TableLayout 中指定了 height=wrap_content,但 f 和 o 超出了按钮的边界。

在 eclipse 的 Layout 选项卡中显示正常,在模拟器中只显示垂直(未在目标硬件上尝试)

其中一个按钮的 getPaddingLeft 在代码的不同位置返回 11。不知道它从哪里得到的,但间距看起来比那个大。我确实有三个按钮并拿走了一个,但是两个和三个按钮都存在问题。

我的布局是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/map_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingTop="8px"
android:paddingBottom="8px"
android:gravity="center"
android:textColor="@color/header_foreground"
android:background="@color/header_background"
android:text="@string/map_header"/>
<TableLayout
android:id="@+id/map_footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingTop="4px"
android:paddingLeft="2px"
android:paddingRight="2px"
android:stretchColumns="*"
android:textColor="@color/footer_foreground"
android:background="@color/footer_background">
<TableRow>
<Button
android:id="@+id/map_infobutton"
android:layout_width="0px"
android:layout_weight="1"
android:text="@string/map_infobutton" />
<Button
android:id="@+id/map_selectbutton"
android:layout_width="0px"
android:layout_weight="1"
android:text="@string/map_selectbutton" />
</TableRow>
</TableLayout>
<LinearLayout
android:id="@+id/map_selectiondetails"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/map_footer"
android:orientation="horizontal"
android:gravity="center"
android:textColor="@color/main_foreground"
android:background="@color/main_background" >
<TextView
android:id="@+id/map_selectionname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="4px"
android:textColor="@color/main_foreground"
android:background="@color/main_background"/>
<TextView
android:id="@+id/map_selectiondistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4px"
android:paddingRight="4px"
android:textColor="@color/main_foreground"
android:background="@color/main_background"/>
<TextView
android:id="@+id/map_selectionvar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4px"
android:paddingRight="4px"
android:textColor="@color/main_foreground"
android:background="@color/main_background"/>
<TextView
android:id="@+id/map_selectionvar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4px"
android:paddingRight="4px"
android:textColor="@color/main_foreground"
android:background="@color/main_background"/>
<TextView
android:id="@+id/map_selectionvar3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4px"
android:textColor="@color/main_foreground"
android:background="@color/main_background"/>
</LinearLayout>
<SurfaceView
android:id="@+id/map_map"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_above="@id/map_selectiondetails"
android:layout_below="@id/map_header"
android:clickable="true"/>

</RelativeLayout>

有什么想法吗?另外,如果您对我如何创建布局有任何意见,因为我是新手,似乎有很多可用选项,但我正在努力使其尽可能简单。

最佳答案

我遇到了类似的问题。

我看到您有多个想要具有相同宽度的按钮,因此您将按钮的宽度指定为“0px”,将粗细指定为“1”。这正是我所做的。

当我在 XML 文件中设置按钮文本时,一切看起来都很好。但是,我有一个按钮会根据进程是否正在运行而更改文本。在我的例子中,它类似于按钮从“开始...”切换到“停止...”的情况,文本更改后,它会垂直打印,并且只显示每个按钮的顶部一两个字母。

看完你的帖子,我想到,也许,文本是在确定按钮宽度之前设置的,然后一旦按钮宽度根据“权重”发生变化就不会更新。

我修改了它,在每个按钮中,它现在显示为:

android:layout_width="fill_parent" 而不是“0px”

理论上,这应该有相同的效果。然而,在实践中,按钮宽度是在文本更新之前调整的。该行为现在是正确的。

罗布

关于android - 按钮文本显示为垂直,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3515131/

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