Prexx
Prexx

Reputation: 2979

No scrolling in scrollview

i have a problem with my scrollview...

my xml:

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

         <ScrollView android:id="@+id/scrollView1" android:layout_width="wrap_content" android:layout_height="match_parent">
             <RelativeLayout [...]>
                 <TextView [...]></TextView>
                 <Spinner [...]></Spinner>
                 <Button [...]></Button>
                 <ImageButton [...]></ImageButton>
                 <TextView [...]></TextView>
                 <TableLayout [...]>
                     <TableRow [...]>
                         <TextView [...]></TextView>
                         <TextView [...]></TextView>
                         <TextView [...]></TextView>
                     </TableRow>
                     <TableRow [...]>
                         <AutoCompleteTextView [...]></AutoCompleteTextView>
                         <AutoCompleteTextView [...]></AutoCompleteTextView>
                         <Spinner [...]></Spinner>
                     </TableRow>
                 </TableLayout>
            </RelativeLayout>
         </ScrollView>
</LinearLayout>

When i try to scroll in my App it wont work... what did i do wrong? i deleted the properties from the elements. if you need them to solve the problem i can add them. i did it to get a better overview.

thanks, prexx

Upvotes: 3

Views: 4459

Answers (4)

Sameer Zinzuwadia
Sameer Zinzuwadia

Reputation: 3285

Please change to android:layout_width="wrap_content" android:layout_height="wrap_content" to fill parent.

Thank you

Upvotes: 0

ffleandro
ffleandro

Reputation: 4041

If the ScrollView content doesn't take up the whole space, it will behave as a normal layout, i.e. non-scrollable.

If you still need the ScrollView to fill the entire screen (but still not scroll since there is not enough content) you could do as Nicholas Magnussen mentioned and add android:fillViewport="true"

Upvotes: 0

Carnal
Carnal

Reputation: 22064

Try adding the ScrollView as the parent. Swich place with LinearLayout. And dont forget to add the following on your ScrollView instead of the LinearLayout:

xmlns:android="http://schemas.android.com/apk/res/android"

And layout_widht and layout_height of the ScrollView should be set to "fill_parent"

This is my code which uses ScrollView in a calendar I made, could help you:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg">
<LinearLayout 
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button android:id="@+id/dayView" android:text="Day" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
    <Button android:id="@+id/weekView" android:text="Week" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
    <Button android:text="Month" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:enabled="false"/>
    <Button android:id="@+id/eventsView" android:text="Events" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/prevMonth"
        android:src="@drawable/calendar_left_arrow_selector"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ImageView>
    <Button
        android:id="@+id/currentMonth"
        android:layout_weight="0.6"
        android:textColor="#FFFFFF"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:background="@drawable/calendar_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </Button>
    <ImageView
        android:id="@+id/nextMonth"
        android:src="@drawable/calendar_right_arrow_selector"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ImageView>
</LinearLayout>
<LinearLayout
    android:layout_gravity="center"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView android:layout_width="wrap_content" android:layout_height="20dp" android:text="Week" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/monday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/tuesday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/wednesday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/thursday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/friday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/saturday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/sunday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/> 
</LinearLayout>
<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_weight="1">
    <ViewFlipper
       android:id="@+id/flipper"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent">
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal">
        <GridView
            android:id="@+id/weeks"
            android:numColumns="1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:scrollbars="none">
        </GridView>
        <GridView
            android:id="@+id/calendar"
            android:numColumns="7"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:scrollbars="none">
        </GridView>
    </LinearLayout>
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal">
        <GridView
            android:id="@+id/weeks2"
            android:numColumns="1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:scrollbars="none">
        </GridView>
        <GridView
            android:id="@+id/calendar2"
            android:numColumns="7"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:scrollbars="none">
        </GridView>
    </LinearLayout>
</ViewFlipper>
</LinearLayout>
<LinearLayout
        android:id="@+id/bottom_layout" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/create_event"
            android:text="Create event"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

Upvotes: 3

Nicholas Magnussen
Nicholas Magnussen

Reputation: 769

Try adding android:fillViewport="true" to your scrollView.

The height of your scrollView should probably be either match_parent or fill_parent aswell.

Upvotes: 2

Related Questions