Scrollview不会滚动

时间:2019-05-23 05:09:36

标签: java android

我已经尝试过,不知道为什么我的滚动视图不起作用。 我已经将Scroll View的子布局更改为wrap_content高度,但仍然无法正常工作。我的按钮如我所愿位于底部,但是内容应该可以滚动,并且我已经在1张卡片视图中切换了内容

<RelativeLayout
    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="wrap_content"
    android:background="@color/grey"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/scrl"
        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">

        <cardview>
        <cardview>
        <cardview>
        <cardview> here i have toggle content

         <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/len_16dp"
                    android:layout_marginTop="@dimen/len_12dp"
                    android:layout_marginRight="@dimen/len_16dp"
                    android:foreground="@drawable/inverted_corners"
                    android:orientation="vertical"
                    tools:ignore="MissingConstraints">

                    <com.prismalink.mbddlibrary.util.UnscrollableList
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentTop="true"
                        android:layout_centerHorizontal="true"
                        android:clickable="false"/>

          </LinearLayout>

      </LinearLayout>

    </ScrollView>

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom|center_horizontal"
    android:orientation="vertical">

    <Button
        android:id="@+id/btnBayar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />
    </LinearLayout>

</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

此代码运行良好,对不起我的小错。只需将其添加到scrollView孩子, 我意识到内容与父母的高度相同

android:paddingBottom="@dimen/len_64dp"

答案 1 :(得分:0)

ScrollView放置为layout的根。

<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:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/grey"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/scrl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">
     .......
     .....