How to use ScrollView + Listview

2

I'm creating a profile system for users using ListView and RecyclerView and I'm not able to make scroll work. Currently it works like this:

WhenIdonotuseScrollView,itjustdoesthescrollofLisViewandthetoppartislocked.WhenIuseScrollView,itstillhasthesameproblem,butitworksfineifIspecifyasizeforlayout_heightotherthanwrap_contentormatch_parente,suchas500dp..butitdoesnottakealltheposts,gettheonesthatgiveaccordingtotheheight.

Ididnotunderstandverywell,IsearchedinsomesitesandIcouldnotsolvethisproblem,IsawinsomeinternationalsitesthatitwouldnotbepossibletouseScrollViewwithinListViewandotherssayingthatithad,butdidnotobtainsuccess,Idonotquiteunderstand,cananyonehelpme?

WhatIreallywantisthatthelistscrollalongwiththepageasshownintheimagebelow,inthecaseofInstagram,Facebookandothers.

Scriptfrommyprofile:

<?xmlversion="1.0" encoding="utf-8"?>

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

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

<android.support.v7.widget.CardView
    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="130dp"
    cardView:cardBackgroundColor="#FFF"
    cardView:cardCornerRadius="4dp"
    android:layout_margin="5dp"
    android:id="@+id/cardview01"
    xmlns:cardView="http://schemas.android.com/apk/res-auto">


<android.support.percent.PercentRelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <de.hdodenhof.circleimageview.CircleImageView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/profileuimage"
    android:layout_width="70dp"
    android:layout_height="70dp"
    app:border_color="#FFF"
    android:src="@drawable/placeholder"
    app:border_width="2dp"
    app:layout_marginLeftPercent="2%"
    app:layout_marginTopPercent="2%"
    app:layout_marginRightPercent="4%"
    app:layout_marginBottomPercent="5%"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ucStatus"
        android:background="@drawable/ic_offline"
        app:layout_marginLeftPercent="15%"
        app:layout_marginTopPercent="35%"/>

    <com.addfrases.addfrases.MyCustomTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#4C4C4C"
        android:textSize="25dp"
        android:id="@+id/profileuname"
        app:layout_marginTopPercent="5%"
        android:layout_toRightOf="@+id/profileuimage" />

    <com.addfrases.addfrases.MyCustomTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#ccc"
        android:textSize="12dp"
        android:id="@+id/profileuregion"
        app:layout_marginTopPercent="30%"
        android:layout_toRightOf="@+id/profileuimage"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_about"
        android:id="@+id/useraboutimg"
        android:layout_below="@+id/profileuimage"
        app:layout_marginLeftPercent="8%"
        app:layout_marginRightPercent="8%" />

    <com.addfrases.addfrases.MyCustomTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/profileuserabout"
        android:textColor="#696969"
        android:textSize="12dp"
        app:layout_marginTopPercent="60%"
        android:layout_toRightOf="@+id/useraboutimg"
        android:allowUndo="false" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/separator"
        android:id="@+id/separator"
        android:layout_below="@+id/profileuserabout"/>

    <Button
        android:layout_width="90dp"
        android:layout_height="30dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="SEGUIR"
        android:textColor="#FFF"
        android:background="@drawable/ic_follower"
        android:id="@+id/followButton"
        android:layout_below="@+id/separator"
        android:backgroundTint="#4B7AB2"
        app:layout_marginLeftPercent="65%" />


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

<android.support.v7.widget.CardView
    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="70dp"
    android:layout_marginTop="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    cardView:cardBackgroundColor="#FFF"
    cardView:cardCornerRadius="4dp"
    android:id="@+id/cardview02"
    xmlns:cardView="http://schemas.android.com/apk/res-auto">


    <android.support.percent.PercentRelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.addfrases.addfrases.MyCustomTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:id="@+id/totalposts"
            android:textSize="20dp"
            android:textColor="#414141"
            android:text="0"
            app:layout_marginLeftPercent="15%"
            app:layout_marginTopPercent="20%"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="PUBLICAÇÕES"
            android:textColor="#4B4F54"
            android:textSize="10dp"
            app:layout_marginLeftPercent="8%"
            android:layout_below="@+id/totalposts"/>

        <com.addfrases.addfrases.MyCustomTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:text="0"
            android:textSize="20dp"
            android:textColor="#34373B"
            android:id="@+id/totalFollowing"
            app:layout_marginLeftPercent="45%"
            app:layout_marginTopPercent="20%"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SEGUINDO"
            android:textColor="#4B4F54"
            android:textSize="10dp"
            app:layout_marginLeftPercent="41%"
            android:layout_below="@+id/totalFollowing"/>

        <com.addfrases.addfrases.MyCustomTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:text="0"
            android:id="@+id/totalFollowerss"
            android:textSize="20dp"
            android:textColor="#34373B"
            app:layout_marginLeftPercent="80%"
            app:layout_marginTopPercent="20%"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SEGUIDORES"
            android:textColor="#4B4F54"
            android:textSize="10dp"
            app:layout_marginLeftPercent="73%"
            android:layout_below="@+id/totalFollowing"/>

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

<view
    android:id="@+id/recycler_view"
    class="android.support.v7.widget.RecyclerView"
    android:layout_width="match_parent"
    android:layout_height="453dp"
    android:layout_marginTop="5dp"
    android:layout_weight="0.31" />

<ProgressBar
    android:id="@+id/progress_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="200dp"
    android:layout_marginTop="250dp"/>
    </LinearLayout></ScrollView></FrameLayout>
    
asked by anonymous 04.05.2016 / 03:37

3 answers

1

use the fillViewport tag in your scroll

android:fillViewport="true"

Your structure will look like this:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true" >

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

        <!-- codigo -->


    </LinearLayout>
</ScrollView>
    
04.05.2016 / 13:07
0

If I understood correctly, you want the ListView that is outlined in red in your question, be an infinite ScrollView until the last post, and the top 2 images are locked.

If so, try the following:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.ajuda.ajuda.MainActivity">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/relativeLayout">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/x">

        </ImageView>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/c"
            android:layout_below="@+id/imageView"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true">

        </ImageView>
    </RelativeLayout>

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

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/relativeLayout">

        <ListView
            android:id="@+id/lista_jornais"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            tools:listitem="@android:layout/simple_list_item_1"
            android:layout_alignParentTop="true" />

        <ScrollView
            android:id="@+id/scrollView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />
    </RelativeLayout>

</RelativeLayout>

The result was this:

    
04.05.2016 / 06:59
0

You forgot to close the tag of your ScrollView. He can only have one child.

Put this line at the end of your code:

<ScrollView/>
    
05.05.2016 / 00:41