gpt4 book ai didi

android - Nexus 7 编译时没有出现按钮

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

我正在编译并运行到 Nexus 7 设备而不是模拟器,因为模拟器在我的 macbook 上运行速度非常慢。

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello" />

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button_send"/>

</LinearLayout>

我正在看一本书,但我不知道自己做错了什么。我正在使用 ADT eclipse ide。有任何想法吗?文本在那里,但按钮没有显示,当我在图形 View 中添加一个按钮时,它似乎在注入(inject)代码时起作用。

最佳答案

LinearLayout 在使用 fill_parent 时,一个一个地测量它的每个 child 需要多少大小。因此,在您的示例中,它看到第一个 child 想要拥有它提供给它的所有可用高度 (fill_parent)。

如果你不关心间距

android:layout_height="fill_parent" 更改为 android:layout_height="wrap_content"

假设您希望按钮位于底部

您可以使用 layout_weight 解决这个问题。告诉两个 View 只使用它们需要的空间(即,使用 wrap_content)。接下来将第一个 View 设置为使用 layout_weight=1,以便在决定哪个 View 获得剩余空间时第一个 View 优先。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Hello" />

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Send"/>

</LinearLayout>

结果如下所示,这就是我假设您想要的:

enter image description here

关于android - Nexus 7 编译时没有出现按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14665588/

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