gpt4 book ai didi

java - ScrollView XML 布局问题

转载 作者:行者123 更新时间:2023-11-29 21:50:48 24 4
gpt4 key购买 nike

希望这是一个简单的。

我有一个使用 ScrollView 的布局。这很好,直到我想在其上方放置一个图像和 TextView ,然后在其下方放置带有我的编辑文本的 ScrollView 。

目前我收到以下错误:

01-22 20:13:32.228: E/AndroidRuntime(275): FATAL EXCEPTION: main
01-22 20:13:32.228: E/AndroidRuntime(275): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.addAppointment}: java.lang.RuntimeException: Binary XML file line #26: You must supply a layout_width attribute.

我曾尝试更改 ScrollView 的宽度属性(我相信错误也指向该属性)但没有成功。

这是我的 XML。谁能看出我做错了什么?:

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

<ImageView
android:id="@+id/imgLink"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/viewcon" />

<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="75dp"
android:gravity="center"
android:text="Appointments"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="35sp" />
</LinearLayout>

\\ERROR: On width attribute
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
android:id="@+id/inputAppName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >

<requestFocus />
</EditText>

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Type:"
android:textAppearance="?android:attr/textAppearanceMedium" />

<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TimePicker
android:id="@+id/timePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />

<DatePicker
android:id="@+id/datePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments:"
android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
android:id="@+id/inputAppCom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Appointment Date Alarm:"
android:textAppearance="?android:attr/textAppearanceMedium" />

<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:textOff="Alarm Off"
android:textOn="Alarm On" />

<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Appointment"
android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
android:id="@+id/btnAddAppointment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add" />

</ScrollView>
</LinearLayout>

编辑:

enter image description here

最佳答案

ScrollView 只能设置一个子布局。我不知道为什么它向您显示您没有设置 android:layout_width 属性,但您的问题肯定是您的 ScrollView 中有多个 subview 。

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

<ImageView
android:id="@+id/imgLink"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/viewcon" />

<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="75dp"
android:gravity="center"
android:text="Appointments"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="35sp" />
</LinearLayout>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >


<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
android:id="@+id/inputAppName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >

<requestFocus />
</EditText>

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Type:"
android:textAppearance="?android:attr/textAppearanceMedium" />

<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TimePicker
android:id="@+id/timePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />

<DatePicker
android:id="@+id/datePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments:"
android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
android:id="@+id/inputAppCom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Appointment Date Alarm:"
android:textAppearance="?android:attr/textAppearanceMedium" />

<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:textOff="Alarm Off"
android:textOn="Alarm On" />

<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Appointment"
android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
android:id="@+id/btnAddAppointment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add" />

</LinearLayout>
</ScrollView>
</LinearLayout>

关于java - ScrollView XML 布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14467362/

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