【问题标题】:Android cant set height to ListView in RelativeLayout inNestedScrollViewAndroid无法在RelativeLayout NestedScrollView中将高度设置为ListView
【发布时间】:2020-01-08 17:48:02
【问题描述】:

所以我在 NestedScrollView 内的 RelativeLayout 内有 ScrollView。一切正常,甚至滚动(由于某种原因,您无法在 ScrollView 中滚动 ListView),但我无法将 ListView 高度设置为实际 wrap_content。由于某种原因,总是在 70dp 左右。我什么都试过了。 知道我该怎么做吗?谢谢!!!

<?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>

【问题讨论】:

标签: android listview android-relativelayout android-nestedscrollview


【解决方案1】:

试试这个;

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 2020-04-17
    • 2013-10-07
    • 1970-01-01
    • 2012-07-13
    • 1970-01-01
    • 2015-09-24
    相关资源
    最近更新 更多