angela angela - 3 months ago 12
Android Question

Images and text go into the header when I scroll

Every time I scroll down the screen, the images and text keep going into the header and interfering with the header, can anyone tell where I went wrong in the xml file? I'm pretty sure it's a small thing but I can't seem to see it. Thank you

screenshot

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
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:paddingBottom="@dimen/activity_vertical_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="ie.example.artur.projectrepeat.ScrollActivity"
android:orientation="vertical"
android:weightSum="1">



<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Potatoe"
android:id="@+id/textView6"
android:layout_weight="0.95"
/>

<ImageView
android:layout_width="178dp"
android:layout_height="71dp"
android:id="@+id/imageView3"
android:layout_gravity="center_horizontal"
android:src="@mipmap/potatoe"
android:layout_weight="0.61"
android:contentDescription="potatoe1" />


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

<ImageView
android:layout_width="178dp"
android:layout_height="71dp"
android:id="@+id/imageView4"
android:layout_gravity="center_horizontal"
android:src="@mipmap/tomatoe"
android:layout_weight="0.44" />

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

<ImageView
android:layout_width="178dp"
android:layout_height="71dp"
android:id="@+id/imageView5"
android:layout_gravity="center_horizontal"
android:src="@drawable/carrot"
android:layout_weight="0.61" />

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

<ImageView
android:layout_width="178dp"
android:layout_height="71dp"
android:id="@+id/imageView6"
android:layout_gravity="center_horizontal"
android:src="@mipmap/potatoe"
android:layout_weight="0.36" />

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

<ImageView
android:layout_width="178dp"
android:layout_height="71dp"
android:id="@+id/imageView7"
android:layout_gravity="center_horizontal"
android:src="@drawable/apples"
android:layout_weight="0.30" />

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

<ImageView
android:layout_width="178dp"
android:layout_height="71dp"
android:id="@+id/imageView8"
android:layout_gravity="center_horizontal"
android:src="@drawable/oranges" />

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

<ImageView
android:layout_width="178dp"
android:layout_height="71dp"
android:id="@+id/imageView9"
android:layout_gravity="center_horizontal"
android:src="@drawable/strawberry" />

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

<ImageView
android:layout_width="178dp"
android:layout_height="71dp"
android:id="@+id/imageView10"
android:layout_gravity="center_horizontal"
android:src="@drawable/bananas" />

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

<ImageView
android:layout_width="178dp"
android:layout_height="71dp"
android:id="@+id/imageView11"
android:layout_gravity="center_horizontal"
android:src="@drawable/letucce" />

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

<ImageView
android:layout_width="178dp"
android:layout_height="71dp"
android:id="@+id/imageView12"
android:layout_gravity="center_horizontal"
android:src="@drawable/pears" />

</LinearLayout>
</ScrollView>

Answer

The problem is not with this XML. It's on the main layout.

  • Your toolbar must be the last element in the XML
  • or you have to use RelativeLayout and android:layout_below
  • or you have to use LinearLayout and orientation="vertical"
Comments