无法在滚动视图中一直向上滚动

时间:2018-09-06 17:15:47

标签: android xml android-layout scrollview

好的,因此在Cardview中的LinearLayout下有此复选框列表。并且我已经添加了一个滚动视图,因为它无法容纳所有滚动视图,并且我想稍后再添加一个滑块。但是问题是,无法使它一直向上滚动,如下图所示。我尝试了在线论坛和某些网站中提供的一些解决方案,例如android:fillViewport="true",但似乎都没有工作。

picture

Page_three.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="top"
    android:fadeScrollbars="true"
    android:fillViewport="true"
    android:scrollbars="vertical">

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        style="@style/CardStyle.Home"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include layout="@layout/pref_check" />
    </android.support.v7.widget.CardView>

</ScrollView>

Pref_check.xml

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingTop="@dimen/view_spacing_small"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/preferences"
        android:textAppearance="@style/TextStyle.Title" />

    <CheckBox
        android:id="@+id/chkBeach"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/beach" />

    <CheckBox
        android:id="@+id/chkBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/bar" />

    <CheckBox
        android:id="@+id/chkMuseum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/museum" />

    <CheckBox
        android:id="@+id/chkRestaurant"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/restaurant" />

    <CheckBox
        android:id="@+id/chkNightClub"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/night_club" />

    <CheckBox
        android:id="@+id/chkArtGallery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/art_gallery" />

    <CheckBox
        android:id="@+id/chkAmusementPark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/amusement_park" />

    <CheckBox
        android:id="@+id/chkCasino"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/casino" />

    <CheckBox
        android:id="@+id/chkClothingStore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/clothing_store" />

    <CheckBox
        android:id="@+id/chkShoppingMall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/shopping_mall" />

    <CheckBox
        android:id="@+id/chkAmusementCenter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/amusement_center" />

    <CheckBox
        android:id="@+id/chkResort"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/Resort" />
</LinearLayout>

Activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <FrameLayout
        android:id="@+id/frame_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_navigation"
        android:animateLayoutChanges="true">

    </FrameLayout>



    <android.support.design.widget.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bottom_navigation"
        android:layout_alignParentBottom="true"
        app:itemBackground="@color/colorPrimary"
        app:itemIconTint="@color/white"
        app:itemTextColor="@color/white"
        app:menu="@menu/navigation"
        />




</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

项目styles configuration肯定存在问题,因为您的布局低于statusbar

在布局的根视图中使用android:fitsSystemWindows="true",在您的情况下使用ScrollView

已编辑

您必须在android:paddingBottom="?attr/actionBarSize"上添加BottomNavigationViewScrollView的任意大小),以使布局位于BottomNavigationView上方。

我已经尝试并测试了代码及其工作

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="top"
    android:fadeScrollbars="true"
    android:fillViewport="true"
    android:paddingBottom="?attr/actionBarSize"
    android:scrollbars="vertical">

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingTop="16dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="adad" />

            <CheckBox
                android:id="@+id/chkBeach"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:checked="false"
                android:onClick="onCheckboxClicked"
                android:text="beach" />

            <CheckBox
                android:id="@+id/chkBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:checked="false"
                android:onClick="onCheckboxClicked"
                android:text="bar" />

            <CheckBox
                android:id="@+id/chkMuseum"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:checked="false"
                android:onClick="onCheckboxClicked"
                android:text="museum" />

            <CheckBox
                android:id="@+id/chkRestaurant"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:checked="false"
                android:onClick="onCheckboxClicked"
                android:text="restaurant" />

            <CheckBox
                android:id="@+id/chkNightClub"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:checked="false"
                android:onClick="onCheckboxClicked"
                android:text="night_club" />

            <CheckBox
                android:id="@+id/chkArtGallery"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:checked="false"
                android:onClick="onCheckboxClicked"
                android:text="art_gallery" />

            <CheckBox
                android:id="@+id/chkAmusementPark"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:checked="false"
                android:onClick="onCheckboxClicked"
                android:text="amusement_park" />

            <CheckBox
                android:id="@+id/chkCasino"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:checked="false"
                android:onClick="onCheckboxClicked"
                android:text="casino" />

            <CheckBox
                android:id="@+id/chkClothingStore"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:checked="false"
                android:onClick="onCheckboxClicked"
                android:text="clothing_store" />

            <CheckBox
                android:id="@+id/chkShoppingMall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:checked="false"
                android:onClick="onCheckboxClicked"
                android:text="shopping_mall" />

            <CheckBox
                android:id="@+id/chkAmusementCenter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:checked="false"
                android:onClick="onCheckboxClicked"
                android:text="amusement_center" />

            <CheckBox
                android:id="@+id/chkResort"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:checked="false"
                android:onClick="onCheckboxClicked"
                android:text="Resort" />
        </LinearLayout>
    </android.support.v7.widget.CardView>

</ScrollView>

答案 1 :(得分:0)

解决了:

我没有将cardview添加到Page_three.xml中,而是将其包装在Pref_check.xml中的LinearLayout周围。

Page_three.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fadeScrollbars="true"
    android:fillViewport="true"
    android:scrollbars="vertical"
    android:fitsSystemWindows="true">
   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="vertical"
       android:paddingTop="@dimen/view_spacing_small">
       <include layout="@layout/pref_check" />

       <include layout="@layout/slider" />
   </LinearLayout>
</ScrollView>

Pref_check.xml

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/CardStyle.Home"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingTop="@dimen/view_spacing_small"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/preferences"
        android:textAppearance="@style/TextStyle.Title" />

    <CheckBox
        android:id="@+id/chkBeach"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/view_spacing_medium"
        android:checked="false"
        android:onClick="onCheckboxClicked"
        android:text="@string/beach" />
          .
          .
          .

</LinearLayout>
</android.support.v7.widget.CardView>
相关问题