2016-04-09 8 views
-1

Hey Jungs/Mädchen Im Erstellen einer Food-Tracker-App für ein Klassenprojekt. Wo der Benutzer einen Spinner hinzufügt, der eine Reihe von Elementen "Nahrung" enthält.Spinner in meinem Layout ist über den Text-Ansicht

Problem: Wenn der Benutzer 6 Essen in der Frühstücksektion hinzufügt, wird es über den nächsten Abschnitt, der Mittagessen wäre. Wie würde ich das beheben? Ich habe es in einer Listenansicht versucht, hatte aber Probleme.

content_main.xml

 <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:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_horizontal_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context=".MainActivity" 
    tools:showIn="@layout/activity_main"> 


    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginTop="49dp" 
     android:text="@string/breakfast" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/textView2" 
     android:layout_marginTop="127dp" 
     android:text="Lunch" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <TextView 
     android:id="@+id/textView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView3" 
     android:layout_marginTop="130dp" 
     android:paddingBottom="130dp" 
     android:text="@string/dinner" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:layout_alignRight="@+id/LLL" 
     android:layout_alignEnd="@+id/LLL" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <LinearLayout 
     android:id="@+id/BLL" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:weightSum="1" 
     android:layout_below="@+id/textView2" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

     <Spinner 
      android:layout_width="240dp" 
      android:layout_height="37dp" 
      android:id="@+id/bkSpinner" 
      android:layout_weight="0.21" 
      android:entries="@array/allFoodItems" /> 






    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/LLL" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/addNewDItem" 
     android:layout_below="@+id/textView3" 
     android:orientation="vertical" 
     android:layout_centerHorizontal="true"> 

     <Spinner 
      android:layout_width="240dp" 
      android:layout_height="37dp" 
      android:id="@+id/LSpinner" 
      android:layout_weight="0.21" 
      android:entries="@array/allFoodItems"/> 
    </LinearLayout> 

    <Button 
     android:id="@+id/addNewLItem" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignTop="@+id/textView3" 
     android:text="@string/LButton" /> 

    <Button 
     android:id="@+id/addNewDItem" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignTop="@+id/textView4" 
     android:text="@string/DButton" /> 

    <LinearLayout 
     android:id="@+id/DLL" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignBottom="@+id/textView4" 
     android:layout_alignEnd="@+id/LLL" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignRight="@+id/LLL" 
     android:orientation="vertical" 
     android:layout_below="@+id/addNewDItem"> 


     <Spinner 
      android:layout_width="240dp" 
      android:layout_height="37dp" 
      android:id="@+id/dnSpinner" 
      android:entries="@array/allFoodItems" /> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/calories" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/total" 
     android:layout_alignEnd="@+id/addNewDItem" 
     android:layout_alignRight="@+id/addNewDItem" 
     android:text="" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#ff0000" 
     android:textSize="12dp"/> 

    <Button 
     android:id="@+id/total" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/textView4" 
     android:text="@string/totalCal" /> 

    <Button 
     android:id="@+id/addNewBItem" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/BButton" 
     android:layout_column="13" 
     android:layout_alignTop="@+id/BLL" 
     android:layout_alignLeft="@+id/addNewDItem" 
     android:layout_alignStart="@+id/addNewDItem" /> 

</RelativeLayout> 

enter image description here

Antwort

0

gestalten Sie Ihre xml 'Zeile für Zeile' mit LinearLayout:

<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:layout_width="match_parent" 
android:layout_height="match_parent"> 


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

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="BrekFast" 
     android:id="@+id/textView"/> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <Spinner 
      android:layout_width="240dp" 
      android:layout_height="37dp" 
      android:id="@+id/bkSpinner" 
      android:layout_weight="0.21" 
      ... /> 
     <Button 
      android:text="Add Breakfast" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      ... /> 

    </LinearLayout> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="BrekFast" 
     android:id="@+id/textView2"/> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <Spinner 
      android:layout_width="240dp" 
      android:layout_height="37dp" 
      android:id="@+id/bkSpinner2" 
      android:layout_weight="0.21" 
     ... /> 
     <Button 
      android:text="Add Breakfast" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
     ... /> 

    </LinearLayout> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="BrekFast" 
     android:id="@+id/textView3"/> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <Spinner 
      android:layout_width="240dp" 
      android:layout_height="37dp" 
      android:id="@+id/bkSpinner3" 
      android:layout_weight="0.21" 
     ... /> 
     <Button 
      android:text="Add Breakfast" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
     ... /> 

    </LinearLayout> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     android:text="Calories Total"/> 



</LinearLayout> 
</ScrollView>