2015-03-30 3 views
-1

Я hava ScrollView с одним RelativeLayout как прямым ребенком и несколькими макетами внутри него. Однако во время выполнения приложения происходит сбой, говоря, что ScrollView может иметь только один прямой дочерний элемент. Какая ошибка я делаю. P.S. Извините, если вопрос был глупым, у меня нет опыта работы с Android-программированием.ScrollView должен иметь только один chilld

<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> 
+0

Существует после

+0

Вам не хватает в конце? –

+0

Нет. Его почему-то не показывают в коде. Я уже упоминал, что присутствует в конце. –

ответ

0

Вы должны обернуть все в пределах scrollView в LinearLayout с помощью wrap_content для высоты.

Этот вопрос уже ответил здесь:

Scrollview can host only one direct child

+0

Не можете ли содержимое обернуть в RelativeLayout? –

+0

Вы можете поместить RelativeLayout в LinearLayout –

+0

Даже это не поможет с проблемой. –

0

Попробуйте добавить относительную макет перед ScrollingView.