Android ScrollView应该只有一个冷态
我有一个ScrollView,其中有一个RelativeLayout作为一个直接的子对象,里面有多个布局。然而,在运行时应用程序崩溃,称ScrollView只能有一个直接子级。我犯了什么错误。 顺便说一句,如果这个问题很愚蠢,我很抱歉,我没有Android编程的经验Android ScrollView应该只有一个冷态,android,android-layout,android-scrollview,Android,Android Layout,Android Scrollview,我有一个ScrollView,其中有一个RelativeLayout作为一个直接的子对象,里面有多个布局。然而,在运行时应用程序崩溃,称ScrollView只能有一个直接子级。我犯了什么错误。 顺便说一句,如果这个问题很愚蠢,我很抱歉,我没有Android编程的经验 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/to
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.appex.android.inquisitor.QuestionActivity"
android:background="@drawable/bg" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:textStyle="bold"
android:id="@+id/textviewname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="150dp"
android:textColor="@color/text2"
android:textSize="13pt"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:id="@+id/edittext1"
android:layout_width="fill_parent"
android:maxLines="1"
android:layout_height="wrap_content"
android:inputType="text"
android:textSize="12pt"
android:textColor="@color/text2"
android:imeOptions="actionDone"
android:layout_gravity="center"
android:layout_below="@+id/textviewname"
android:layout_marginTop="15dp"
/>
<TextView
android:layout_width="wrap_content"
android:textStyle="bold"
android:layout_height="wrap_content"
android:id="@+id/hintview"
android:textSize="12pt"
android:textColor="@color/text2"
android:layout_below="@+id/edittext1"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/done_button"
android:textSize="12pt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="@string/done_button"
android:background="@android:color/transparent"
android:textColor="@color/text2"
android:layout_alignTop="@+id/hintbutton"
android:layout_marginLeft="189dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12pt"
android:textStyle="bold"
android:id="@+id/hintbutton"
android:text="@string/hintbutton"
android:background="@android:color/transparent"
android:textColor="@color/text2"
android:layout_marginLeft="101dp"
android:layout_marginTop="14dp"
android:layout_below="@+id/hintview"
/>
<TextView
android:id="@+id/attemptview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text2"
android:textSize="10pt"
android:layout_marginTop="75dp"
android:layout_alignLeft="@+id/done_button"
android:layout_alignStart="@+id/done_button"
/>
</RelativeLayout>
</ScrollView>
您应该将scrollView中的所有内容包装成线性布局,并将包装内容作为高度 这里已经回答了这个问题:
尝试在滚动视图之前添加一个相对布局。末尾缺少一个after you missing?否。由于某些原因,它没有显示在代码中。我已经在最后提到了存在。当您在Scrollview中查找多个主子级,但将其正确放置在代码中时,显然会发生这种情况。请尝试刷新项目并重新运行。刷新项目没有帮助。内容不能包装在RelativeLayout中吗?您可以将RelativeLayout放在LinearLayout即使这样也无助于解决问题。