Android ScrollView not scrolling

2019-03-22 05:36发布

问题:

I have solved my question. I chose to instead have a header and a footer that are always located at the bottom and top of the screen respectively. Then I created a "center content" which I enclosed within a ScrollView layout. I have updated the code below if people are interested in seeing what it now looks like.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:background="#FFFFFF">

    <LinearLayout android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@layout/header"
        android:layout_alignParentTop="true">
        <ImageView android:src="@drawable/logo"
            android:contentDescription="@string/logo_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dip"/>
    </LinearLayout>

    <ScrollView android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="350dip"
        android:layout_below="@id/header">
        <LinearLayout android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="20dip" >
            <!--  Email Label -->
            <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#372C24"
                android:text="@string/email"/>
            <EditText android:id="@+id/email_field"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dip"
                android:singleLine="true"
                android:inputType="textEmailAddress"/>
            <!--  Password Label -->
            <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dip"
                android:textColor="#372C24"
                android:text="@string/password"/>
            <EditText android:id="@+id/password_field"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:inputType="textPassword"/>
            <!-- Login button -->
            <Button android:id="@+id/login_button"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="25dip"
                android:text="@string/login"/>
            <!-- Register button -->
            <Button android:id="@+id/register_button"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="25dip"
                android:text="@string/register_button"/>
        </LinearLayout>
    </ScrollView>

    <LinearLayout android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="90dip"
        android:background="@layout/footer"
        android:layout_alignParentBottom="true">
    </LinearLayout>

</RelativeLayout>

回答1:

For me, remove android:windowSoftInputMode="adjustPan" of the <activity> tag in AndroidManifest.xml file solved the problem.



回答2:

I removed this line from the AndroidManifest.xml file

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

and added this line

android:theme="@android:style/Theme.NoTitleBar"

it has both fixed my scrolling app and made my app look more visually appealing. However, I am not sure if this is the correct fix.



回答3:

for me the problem was that the LinearLayout in the ScrowView had android:layout_height="wrap_content".

<ScrollView android:id="@+id/scroll_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >

<LinearLayout android:id="@+id/layout_inside"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" --> This should not we wrap_content, but specific height.
    android:orientation="vertical" >


回答4:

The ScrollView is not working when used as the root element of an XML layout. It has to be wrapped inside a LinearLayout.

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

<ScrollView android:id="@+id/scroll_view1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true" >

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

Have a fun ! !



回答5:

ScrollView must have Linearlayout control as a immediate child, you have relative layout, I think that might be causing the problem.

Check this link out, also this. Look at their layout xmls..