2013-04-09 4 views
0

У меня возникает ошибка, говорящая, что Scrollview может содержать только одного ребенка. Я пытаюсь сделать так, чтобы весь интерфейс прокручивал минус объявление вверху. Теперь, когда он стоит, у меня появилось объявление в линейном макете, в котором есть прокрутка. Внутри scrollview есть еще один линейный макет, и все остальное внутри этого. Я не понимаю, что делать. Мне действительно нужно, чтобы объявление не прокручивалось, но если мне придется разместить рекламный код внутри scrollview, я это сделаю. Я просто уверен, что есть способ сделать то, что я хочу, хотя я не могу его найти.Scrollview с объявлением сверху, которое не прокручивается

Вот мой макет XML ...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:id="@+id/AdLinearLayout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<!-- Ad Placeholder --> 

<com.google.ads.AdView 
    android:id="@+id/adView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ads:adSize="BANNER" 
    ads:adUnitId="a15138b1a7adad2" 
    ads:loadAdOnCreate="true" /> 

<ScrollView 
    android:id="@+id/BaseScrollView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <LinearLayout 
     android:id="@+id/baseVerticalLinearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:id="@+id/LinearLayoutH1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="left" 
       android:text="@string/Sad" /> 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="right" 
       android:text="@string/Happy" /> 
     </LinearLayout> 

     <SeekBar 
      android:id="@+id/happinessBarID" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:max="@integer/SliderMax" 
      android:progress="@integer/SliderDefault" /> 

     <LinearLayout 
      android:id="@+id/LinearLayoutH2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/textView3" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="left" 
       android:text="@string/Tired" /> 

      <TextView 
       android:id="@+id/textView4" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="right" 
       android:text="@string/Awake" /> 
     </LinearLayout> 

     <SeekBar 
      android:id="@+id/energyBarID" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:max="@integer/SliderMax" 
      android:progress="@integer/SliderDefault" /> 

     <LinearLayout 
      android:id="@+id/LinearLayoutH3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/textView5" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="left" 
       android:text="@string/Calm" /> 

      <TextView 
       android:id="@+id/textView6" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="right" 
       android:text="@string/Anxious" /> 
     </LinearLayout> 

     <SeekBar 
      android:id="@+id/anxietyBarID" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:max="@integer/SliderMax" 
      android:progress="@integer/SliderDefault" /> 

     <LinearLayout 
      android:id="@+id/LinearLayoutH4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/textView7" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="left" 
       android:text="@string/No_Pain" /> 

      <TextView 
       android:id="@+id/textView8" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="right" 
       android:text="@string/Max_Pain" /> 
     </LinearLayout> 

     <SeekBar 
      android:id="@+id/painBarID" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:max="@integer/SliderMax" 
      android:progress="@integer/SliderDefault" /> 

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

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

     <EditText 
      android:id="@+id/noteTextFieldID" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="@string/Note_Hint" 
      android:inputType="textMultiLine" 
      android:maxLength="@integer/NoteLimit" /> 

     <Button 
      android:id="@+id/enterButtonID" 
      android:layout_width="132dp" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:onClick="dialogPop" 
      android:text="@string/EnterButtonText" /> 
    </LinearLayout> 
</ScrollView> 

</LinearLayout> 
+0

Что не работает? – nhaarman

+0

Похоже, что этот ScrollView имеет только одного ребенка ... Повторное сохранение этого файла и очистка проекта. – Sam

+0

Я попробую. Я не могу понять, почему это не нравится прокрутка, но я дам ему очистить. (Хотя, если я правильно помню, я вчера несколько раз очищал проект, пока я работал над этим.) – fauxfire76

ответ

1

Вот слегка измененная версия примера Scrollview макет из Ad Catalog проекта с AdMob:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <com.google.ads.AdView android:id="@+id/adView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     ads:adUnitId="@string/admob_id" 
     ads:adSize="BANNER"/> 
    <ScrollView android:id="@+id/scrollLayout" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:layout_below="@id/adView"> 
     <LinearLayout android:layout_height="fill_parent" 
      android:layout_width="fill_parent"> 
      <TextView android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:text="@string/advancedLayouts_scroll_view_lorem_ipsum"/> 
     </LinearLayout> 
    </ScrollView> 
</RelativeLayout> 

Вы не хотите, чтобы объявление быть на вершине своей ScrollView, так что вы хотите явно указать он сидит ниже com.google.ads.AdView.

+0

Спасибо. Я смог заставить пользовательский интерфейс работать отлично, кроме того, что теперь он хочет наложить рекламу поверх моего приложения, вместо того, чтобы перемещать пользовательский интерфейс вниз для размещения. Любая идея, как мне это нужно сделать? – fauxfire76

+0

Вы добавили эту строку в свой ScrollView или элемент сиблинга AdView: 'android: layout_below =" @ id/adView "'? Это должно позаботиться об этом. –

0

Это работает для меня идеально, пожалуйста, скажите мне, если больше требуется помощь.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="xxxxxx" /> 

    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <ScrollView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/scrollView" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/back3" > 

      <LinearLayout 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:gravity="center_horizontal" 
       android:orientation="vertical" > 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="top|center_horizontal" 
        android:layout_marginTop="5dp" 
        android:text="Text" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical|center_horizontal" 
        android:layout_marginBottom="20dp" 
        android:text="Text2" /> 
      </LinearLayout> 
     </ScrollView> 
    </RelativeLayout> 

</LinearLayout> 
+0

Как это отличается от того, что у меня есть, кроме того, что слой relativelayout находится между внешним Lingleayout и scrollview? – fauxfire76

Смежные вопросы