Background of the ScrollView causes apps crash

Viewed 84

I struggle to create a reading app with a UI background. The point is that my background needs to be scrollable as well as the text. So I've decided just to put in my app a large jpg with the size of my scroll (992x10901px). The app just doesn't want to start like this.

Btw, at least I see the background in the Design View if I specify the size in px. In dp it isn't displayed.

enter image description here

Please, give me some advice, how to proceed.

My xml:

<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.android.scrollingtext.MainActivity">

<TextView
    android:id="@+id/article_heading"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:padding="@dimen/padding_regular"
    android:text="@string/article_title"
    android:textAppearance="@android:style/TextAppearance.Large"
    android:textColor="@android:color/white"
    android:textStyle="bold" />

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/article_heading">

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

        <ImageView
            android:layout_width="992px"
            android:layout_height="10901px"
            android:src="@drawable/background"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <TextView
                android:id="@+id/article_subheading"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="@dimen/padding_regular"
                android:text="@string/article_subtitle"
                android:textAppearance="@android:style/TextAppearance" />

            <TextView
                android:id="@+id/article1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoLink="web"
                android:lineSpacingExtra="@dimen/line_spacing"
                android:text="@string/article_text" />

            <TextView
                android:id="@+id/article2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoLink="web"
                android:lineSpacingExtra="@dimen/line_spacing"
                android:text="@string/article_text" />
        </LinearLayout>
    </RelativeLayout>
</ScrollView>
2 Answers

It's simple.

add the background in RelativeLayout

like this: android:background="@drawable/background"

You don't need to set a background with height equal to your scroll view instead set your parent layout background, it will be visible throughout the scrollView.

And from your image it looks like you have a solid color background. instead of a jpg, simply use a drawable.

Related