Yagami
Yagami

Reputation: 1

Make scrollview in layout (crash)

I'm trying to make a screen scrollable with scroll view but my application keeps crashing. What I've done is to replace RelativeLayout by ScrollView, but it doesn't work. I need your help with this. Here is the code of the screen:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="0dp"
android:background="@drawable/background01"
tools:context=".MainActivity"
android:id="@+id/relativeLayout">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/id"
    android:background="@drawable/lightcontainer"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:weightSum="1"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:layout_marginBottom="16dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/mainTitle1"
        android:id="@+id/textView"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dp"
        android:textSize="20sp"
        android:textColor="#ffffff"
        android:shadowColor="#000000"
        android:shadowRadius="1.5"
        android:shadowDx="2"
        android:shadowDy="2"/>

</LinearLayout>

Upvotes: 0

Views: 448

Answers (1)

RavingDevs
RavingDevs

Reputation: 11

what you are trying to do is not an scrollable view it's just a relative layout. Try to put your code inside a ScrollView component, like this:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

    <!-- PUT YOUR CODE HERE -->

</ScrollView>

Make sure you close all tags correctly as well (your relative layout is not closed).

<RelativeLayout>
 Content
</RelativeLayout> <-- This closing tag is always necessary

Upvotes: 1

Related Questions