0

So, recently I've been trying to make a layout for my app. I basically need one TextView, one ImageView under it, then one ListView and one more multi-line TextView. So, everything up-to ListView is completely visible. At the bottom of the screen there is ListView, with 1.5 element visible, and the list itself can be scrolled. However, there is no trace of that TextView under it, and the fact that only small part of ListView is visible is annoying. However, my ListView should contain a maximum of 6-8 elements, so is there any easy trick to put a ScrollView as a parent of all this and to make my ListView and TextView below it visible completely? Something like fixing the size of that ListView so it doesn't have to scroll and cause that problem when being into ScrollView, which I have read about a thousand times? Thanks in advance! Hope someone will help cuz I urgently need this. I'm beginner in Android development, but doing good so far. Thanks again.

Edit: So, here is what i did:

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

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

        <TextView
            android:id="@+id/tvTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"
            android:text="Large Text"
            android:textSize="25sp" />

        <ImageView
            android:id="@+id/ivPicture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="18dp"
            android:src="@drawable/android" />

        <ListView
            android:id="@+id/lvElements"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="23dp" >
        </ListView>

        <TextView
            android:id="@+id/tvDesc"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp" >
        </TextView>
    </LinearLayout>

</ScrollView>

But still, the ListView is not scrollable now and it shows only first element. However, I can see last TextView. What now?

Luka Bulatovic
  • 357
  • 5
  • 19
  • I'm not sure O_o I'm removing my answer so other people will attempt to solve it for you. – Piovezan Feb 05 '14 at 21:22
  • 1
    NEVER put a ListView inside a ScrollView, see http://stackoverflow.com/questions/3495890/how-can-i-put-a-listview-into-a-scrollview-without-it-collapsing – 2Dee Feb 05 '14 at 22:38

2 Answers2

0

Remove ScrollView this is sample code try this

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" >

    <TextView
        android:id="@+id/tvTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="Large Text"
        android:textSize="25sp" />

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

    <ListView
        android:id="@+id/lvElements"
        android:layout_width="wrap_content"
        android:layout_height="67dp"
        android:layout_marginTop="23dp"
        android:layout_weight="0.79" >
    </ListView>

    <TextView
        android:id="@+id/tvDesc"
        android:layout_width="fill_parent"
        android:layout_height="14dp"
        android:layout_marginTop="20dp"
        android:layout_weight="0.06"
        android:text="Last text" >

    </TextView>

</LinearLayout>

you can edit android:layout_height="67dp" this code inside ListView .

Tanim reja
  • 2,120
  • 1
  • 16
  • 23
0

Nesting a ListView in a ScrollView is a bad idea. Instead, you could add the views above your ListView as a header and below as the footer: Put the views in a new layout for the header and a separate one for the footer. Then you can do listview.addHeaderView(headerView) and listview.addFooterView(footerView). This will make your entire ListView scroll smoothly.

Check out this example on how to add them Android listview with header and footer buttons

Community
  • 1
  • 1
ono
  • 2,984
  • 9
  • 43
  • 85