Michael Benzo
Michael Benzo

Reputation: 11

Android - NestedScrollView doesn't scroll

I have a problem with xml. When I create a NestedScrollView in android studio, it doesn't scroll in the xml preview. It is so important because if I don't see preview I can't see my work. Also when I start the application, I see the latest version that should no longer be there because it was replaced by this code.

Here is my xml code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    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="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="mn.cdr.du.farnext.insertionActivity.InsertionActivity"
    tools:showIn="@layout/activity_insertion"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/icon_static"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/carouselView"
            android:paddingBottom="20dp"
            android:paddingLeft="30dp"
            android:paddingRight="30dp"
            android:paddingTop="20dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/cash_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_paper_bill" />

                <TextView
                    android:id="@+id/cash_value"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/cash_icon"
                    android:text="100€" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/bed_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_airline_seat_individual_suite_black_24dp" />

                <TextView
                    android:id="@+id/bed_value"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/bed_icon"
                    android:layout_marginLeft="10dp"
                    android:paddingBottom="5px"
                    android:text="4" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/people_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_people_black_24dp" />

                <TextView
                    android:id="@+id/people_value"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="200" />

            </LinearLayout>

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

                <ImageView
                    android:id="@+id/rating_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_star_black_24dp" />

                <TextView
                    android:id="@+id/rating_value"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="3.5/5" />
            </LinearLayout>

        </LinearLayout>

        <android.support.v7.widget.CardView
            android:id="@+id/card_contact"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/icon_static">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="20dp"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:src="@drawable/ic_call_black_24dp" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="60dp"
                android:layout_marginTop="5dp"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/contact_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Phone"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/contact_value"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="+39 1234567890" />
            </LinearLayout>
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:id="@+id/card_address"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/card_contact"
            android:layout_marginTop="10dp">

            <ImageView
                android:id="@+id/address_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="20dp"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:src="@drawable/ic_place_black_24dp" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="60dp"
                android:layout_marginTop="5dp"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Address"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/address_value"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="La Farneta, 56048 Province of Pisa" />
            </LinearLayout>

        </android.support.v7.widget.CardView>

        <TextView
            android:id="@+id/txt_place_card"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/card_address"
            android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txt_place_card"
            android:text="Services" />

    </RelativeLayout>

</android.support.v4.widget.NestedScrollView>

Upvotes: 1

Views: 5756

Answers (4)

Khemraj Sharma
Khemraj Sharma

Reputation: 59004

This is not issue of height of NestedScrollView

New Android Studio has issues with scrolling ScrollView in Layout Editor. In older versions ScrollView had smooth scrolling behavior in Editor. This is a bug of Android Studio.

Solution that i usually do

  • You can see Design & Text at bottom of Layout Editor. Click on Design, there you will be able to scroll. It works perfectly all times i do.
  • If you want Text Editor scrollable, then restart your IDE (File>Invalidate Cache/ Restart>Just Restart). My Text Editor start working by this trick.
  • Just a work around : You can make your upper views invisible temporarily to see your bottom views.

Upvotes: 1

C-Spydo
C-Spydo

Reputation: 799

ScrollViews usually don't scroll in the XML preview. You can only see them on the device. That's why its always better to have an android phone connected to your system for live testing.

That way, you can easily correct any errors

Upvotes: 0

Sanjay Hadiya
Sanjay Hadiya

Reputation: 945

just change this code in your xml The height of the NestedScrollView Always match_parent

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="mn.cdr.du.farnext.insertionActivity.InsertionActivity"
    tools:showIn="@layout/activity_insertion"
    android:paddingLeft="20dp"
    android:paddingRight="20dp">

    <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

 ....
 ....
     ....

</RelativeLayout>

</android.support.v4.widget.NestedScrollView>

Upvotes: 1

Ugurcan Yildirim
Ugurcan Yildirim

Reputation: 6142

The height of the NestedScrollView should be match_parent. And the child of it (RelativeLayout) should have height wrap_content.

Upvotes: 0

Related Questions