gpt4 book ai didi

java - 基本 Android xml GUI 的问题

转载 作者:行者123 更新时间:2023-12-01 15:44:25 25 4
gpt4 key购买 nike

我刚刚开始使用 XML 开发基本的 Android GUI - 当我运行它时,logcat 告诉我“二进制 XML 文件第 16 行:您必须提供一个layout_width 属性。”

当我尝试该程序时,它会抛出错误“应用程序 HelloAndroid 已意外停止。

这是基本的 hello Android 代码 - 更新 - 到目前为止已经知道了!谢谢您的帮助! :)

最佳答案

您的布局中有一部分:

<TextView  
android:text="@string/main_title"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
android:marginBuottom="20dip"
android:textSize="24.5sp" />

正如您已经从此处突出显示的代码中看到的,该元素的某些部分是黑色的。那是因为您通过第二行的 /> 关闭了这个 TextView 。所有其他参数不再属于该元素。因此解析器找不到 layout_widthlayout_height 等 - 并提示这一点(“你没有指定......”)。删除顶部的 /> 就可以了。

编辑:正确的版本应如下所示:

<TextView  
android:text="@string/main_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:marginBottom="20dip"
android:textSize="24.5sp" />

或者(因为这是简写版本

<TextView  
android:text="@string/main_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:marginBottom="20dip"
android:textSize="24.5sp"> </TextView>

关于java - 基本 Android xml GUI 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7380497/

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