Android cant set height to ListView in RelativeLayout inNestedScrollView

58 views Asked by At

So I have ScrollView inside RelativeLayout inside NestedScrollView. Everything works fine, even scroll (for some reason you souldnt be able to scroll ListView inside ScrollView), except I cant set ListView height to actually wrap_content. For some reason is always around 70dp. I tried everything on everything. Any idea how could I do that? Thanks!!!

<?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:id="@+id/nscw"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:fillViewport="true"
    tools:context=".ShowRecipe">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="1000dp">

        <ListView
            android:id="@+id/LV2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/TV1"
            android:paddingRight="7dp"
            android:paddingLeft="7dp"
            android:layout_marginTop="10dp" />

        <TextView
            android:id="@+id/TV1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/LV1"
            android:layout_marginTop="20dp"
            android:layout_centerHorizontal="true"
            android:text="FIRST LIST VIEW"
            android:textAlignment="center"
            android:gravity="center"
            android:textSize="30sp" />

        <TextView
            android:id="@+id/TV2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="SECOND LIST VIEW"
            android:textAlignment="center"
            android:textSize="30sp" />

        <ListView
            android:id="@+id/LV1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:paddingRight="7dp"
            android:paddingLeft="7dp"
            android:layout_below="@+id/TV2"
            android:layout_marginTop="10dp" />


    </RelativeLayout>

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

There are 1 answers

0
S.Grain On

Try this;

<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:id="@+id/nscw"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true">

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

    <ListView
        android:id="@+id/LV2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/TV1"
        android:paddingRight="7dp"
        android:paddingLeft="7dp"
        android:layout_marginTop="10dp" />

    <TextView
        android:id="@+id/TV1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/LV1"
        android:layout_marginTop="20dp"
        android:layout_centerHorizontal="true"
        android:text="FIRST LIST VIEW"
        android:textAlignment="center"
        android:gravity="center"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/TV2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="SECOND LIST VIEW"
        android:textAlignment="center"
        android:textSize="30sp" />

    <ListView
        android:id="@+id/LV1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:paddingRight="7dp"
        android:paddingLeft="7dp"
        android:layout_below="@+id/TV2"
        android:layout_marginTop="10dp" />


</LinearLayout>