简体   繁体   中英

scrolling doesn't work even when using <ScrollView> (Android Studio)

I've tried every solution I could find on different sites, but couldn't find anything, hopefully someone here could help me. There are no errors, just doesn't work to scroll.

<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="385dp"
    android:layout_height="540dp"
    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="gino.navigationface.bar_position"
    tools:showIn="@layout/app_bar_bar_position">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView"
        android:padding="10dp"
        android:scrollIndicators="top|left|bottom|start|end|right">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="The Queen"
                android:id="@+id/textView3"
                android:layout_gravity="center_horizontal"
                android:textStyle="bold|italic"
                android:textSize="30dp"
                android:textColor="#c0c0c0" />

            <Button
                android:layout_width="250dp"
                android:layout_height="100dp"
                android:text=""
                android:background="@drawable/the_queen"
                android:id="@+id/queenButton"
                android:onClick="theQueen"
                android:longClickable="false"
                android:nestedScrollingEnabled="true"
                android:gravity="center_vertical"
                android:foregroundGravity="center_vertical"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="50dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Vasa Bar"
                android:id="@+id/textView4"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="40dp"
                android:textStyle="bold|italic"
                android:textSize="30dp"
                android:textColor="#c0c0c0" />

            <Button
                android:layout_width="150dp"
                android:layout_height="120dp"
                android:text=""
                android:id="@+id/vasabar"
                android:background="@drawable/vasa_bar"
                android:onClick="vasaBar"
                android:gravity="center_vertical"
                android:layout_centerVertical="true"
                android:layout_centerHorizontal="true"
                android:layout_gravity="center_horizontal"
                android:foregroundGravity="center_vertical" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Italienska"
                android:id="@+id/textView5"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="40dp"
                android:textSize="30dp"
                android:textStyle="bold|italic"
                android:textColor="#c0c0c0" />

            <Button
                android:layout_width="250dp"
                android:layout_height="100dp"
                android:id="@+id/button"
                android:background="@drawable/italienska"
                android:layout_gravity="center_horizontal" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Large Text"
                android:id="@+id/textView6"
                android:layout_gravity="center_horizontal"
                android:textSize="30dp"
                android:textStyle="bold|italic"
                android:textColor="#c0c0c0"
                android:layout_marginTop="40dp">
                </TextView>

            <Button
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:id="@+id/källarn"
                android:background="@drawable/kallarn"
                android:layout_gravity="center_horizontal" />

        </LinearLayout>
    </ScrollView>
</LinearLayout>

If needed I could post screenshots of the app

Use this It will work

 <ScrollView
        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:id="@+id/scrollView"
    android:scrollIndicators="top|left|bottom|start|end|right"
    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="gino.navigationface.bar_position"
    tools:showIn="@layout/app_bar_bar_position">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
.................
    </LinearLayout>
    </ScrollView>

Use ScrollView as the root view of layout:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/scroller"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <LinearLayout>
     ...
  </LinearLayout>
</ScrollView>

If you use LinearLayout as root view, is won't scroll even you put an ScrollView inside LinearLayout.

I found the problem in the app_bar_bar_position.xml , I placed the android:background in thewhich made the scrolling not work

< android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true" tools:context="gino.navigationface.bar_position" android:background="@drawable/background_blank">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_bar_position" />

sometimes the answer is simple. if we use scrollView just check once, in the emulator, instead of scrolling with mouse button, drag the screen down using mouse. I had stuck there using mouse scroll button but actually in emulator it works with screen drag down by mouse.

Just check once:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM