ScrollView Android Crashing



这是logcat。以下是我在Android上的注册表格的代码,因为该表格很长并且不适合我的屏幕,所以我想向其添加ScrollView,不幸的是,ScrollView在加载时滚动案件正在崩溃。是super.oncreate(savedinstancestate(; setContentView(r.layout.activity_register(;有人可以帮帮我吗?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/b15"
tools:context="com.Register">
<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="0dp"
            android:padding="10dp"
            app:srcCompat="@drawable/evote" />

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:id="@+id/lnlUsername"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/imageView">

            <EditText
                android:id="@+id/txtUsername"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="45dp"
                android:layout_weight="0.01"
                android:ems="30"
                android:hint="Student ID"
                android:inputType="textPersonName"
                android:textSize="14sp" />

        </LinearLayout>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:id="@+id/lnlFirstname"
            android:layout_below="@+id/lnlUsername"
            android:layout_alignParentStart="true">
            <EditText
                android:id="@+id/txtFirstname"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="45dp"
                android:layout_weight="0.01"
                android:ems="30"
                android:hint="Firstname"
                android:inputType="textPersonName"
                android:textSize="14sp" />

        </LinearLayout>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:id="@+id/lnlSurname"
            android:layout_below="@+id/lnlFirstname"
            android:layout_alignParentStart="true">
            <EditText
                android:id="@+id/txtSurname"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="45dp"
                android:layout_weight="0.01"
                android:ems="30"
                android:inputType="textPersonName"
                android:hint="Surname"
                android:textSize="14sp" />

        </LinearLayout>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:id="@+id/lnlEmail"
            android:layout_below="@+id/lnlSurname"
            android:layout_alignParentStart="true">
            <EditText
                android:id="@+id/txtEmail"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="45dp"
                android:layout_weight="0.01"
                android:ems="30"
                android:inputType="textEmailAddress"
                android:hint="Email"
                android:textSize="14sp" />

        </LinearLayout>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:id="@+id/lnlFaculty"
            android:layout_below="@+id/lnlEmail"
            android:layout_alignParentStart="true"
            android:weightSum="1">
            <Spinner
                android:id="@+id/spfaculty"
                android:layout_width="match_parent"
                android:layout_height="39dp"
                android:layout_marginStart="45dp"
                android:entries="@array/faculty_arrays"
                android:prompt="@string/faculty_prompt"
                android:layout_weight="0.83" />

        </LinearLayout>


        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:id="@+id/lnlSpquestions"
            android:layout_below="@+id/lnlFaculty"
            android:layout_alignParentStart="true"
            android:weightSum="1">
            <Spinner
                android:id="@+id/spquestions"
                android:layout_width="match_parent"
                android:layout_height="39dp"
                android:layout_marginStart="45dp"
                android:entries="@array/question_arrays"
                android:prompt="@string/question_prompt"
                android:layout_weight="0.83" />

        </LinearLayout>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:id="@+id/lnlAnswer"
            android:layout_below="@+id/lnlSpquestions"
            android:layout_alignParentStart="true">
            <EditText
                android:id="@+id/txtAnswer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="45dp"
                android:layout_weight="0.01"
                android:ems="30"
                android:hint="Answer"
                android:inputType="textPersonName"
                android:textSize="14sp" />

        </LinearLayout>


        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:id="@+id/lnlPassword"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/lnlAnswer">

            <EditText
                android:id="@+id/txtPassword"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="45dp"
                android:layout_weight="0.01"
                android:ems="30"
                android:inputType="textPassword"
                android:hint="Password"
                android:textSize="14sp" />

        </LinearLayout>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:id="@+id/lnlConfirmPassword"
            android:layout_below="@+id/lnlPassword"
            android:layout_alignParentStart="true">
            <EditText
                android:id="@+id/txtConfirmPassword"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="45dp"
                android:layout_weight="0.01"
                android:ems="30"
                android:inputType="textPassword"
                android:hint="Confirm Password"
                android:textSize="14sp" />

        </LinearLayout>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:id="@+id/lnlRegister"
            android:layout_below="@+id/lnlConfirmPassword"
            android:layout_alignParentStart="true">
            <Button
                android:id="@+id/btnregisterstudent"
                style="@style/Base.TextAppearance.AppCompat.Body2"
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:layout_centerHorizontal="true"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:background="#ff944d"
                android:clickable="true"
                android:layout_marginStart="20dp"
                android:padding="10dp"
                android:layout_marginEnd="20dp"
                android:text="Register"
                android:textAllCaps="false"
                android:textColor="#fff"
                android:textSize="15sp" />

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

记住

ScrollView只带一个孩子...您的卷轴有一个以上...

因此,尝试在scrollview

的一个孩子中结合图像视图和其他布局

您可以做一件事,在scrollview下结合一个相对布局,并在滚动浏览上关闭。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/b15"
        tools:context="com.Register"
        >
        //add your view here
        ....
    </RelativeLayout>
</ScrollView>

请记住,只需在root上添加此Android名称空间

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

在儿童查看Android名称空间上,没有必要

最新更新