Ortensia C.
Ortensia C.

Reputation: 4716

ScrollView with LinearLayout inside does not work

I have a scrollView with two inside LinearLayout but it does not work, the listView does not show all items but only a few. How can I do?

  <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">

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



    <LinearLayout
        android:id="@+id/welcomeView"
        android:layout_width="250dp"
        android:layout_height="100dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:gravity="center"
        android:orientation="horizontal"
        android:weightSum="100" >

        <ImageView
            android:id="@+id/image_User_welcome"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_weight="70"
            android:src="@drawable/user" />

        <TextView
            android:id="@+id/private_area_welcome"
            style="@style/CoopLabel"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_weight="30"
            android:text="@string/private_area_welcome" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:orientation="vertical"
        android:layout_below="@+id/welcomeView">       
    <TextView
        android:id="@+id/private_area_lists"
        style="@style/CoopLabel"
        android:layout_width="280dp"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/linearLayout1"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:gravity="center"
        android:text="@string/private_area_lists" />

    <ListView
        android:id="@+id/privareaList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:textColor="#000000" >
    </ListView>

    <ImageButton
        android:id="@+id/logoutBtn"
        android:layout_width="160dp"
        android:layout_height="35dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:padding="0dp"
        android:scaleType="centerCrop"
        android:src="@drawable/tasto_logout"
        />

    </LinearLayout>

   </RelativeLayout>

   </ScrollView>  

Upvotes: 0

Views: 2288

Answers (1)

Berť&#225;k
Berť&#225;k

Reputation: 7322

It is not recommended to use scrollables containing other scrollables - your layout contains ListView inside Scrollview.

You can design your layout as a ListView - you can add header and footer views(welcomeView, logoutBtn, etc..) to the top and bottom of listview - see methods ListView.addHeaderView and addFooterView) - scrolling will be managed by ListView,

or you can replace listview in your original layout with simple LinearLayout and populate it manually row by row(do not forget to assign click listeners to rows etc..) - scrolling will be managed by ScrollView.

To find more information about this problem, try to google "android listview inside scrollview", i am sure it will help you. :-)

Upvotes: 2

Related Questions