无法在滚动视图中一直向上滚动
Couldn't scroll all the way up in scroll view
好的,在 LinearLayout 下的 cardview 中有这个复选框列表。并且我添加了一个滚动视图,因为它无法容纳所有视图,我想稍后添加一个滑块。但问题是我无法让它一直向上滚动,如图所示 below.I 已经尝试了一些在线论坛和某些网站上提供的解决方案,例如 android:fillViewport="true"
,但是 none 其中似乎有效。
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>
您项目的 styles configuration
一定有问题,因为您的布局低于 statusbar
。
在您的布局的根视图中使用 android:fitsSystemWindows="true"
,ScrollView
您的情况。
已编辑
您必须将 android:paddingBottom="?attr/actionBarSize"
(BottomNavigationView
的任何尺寸)添加到您的 ScrollView
,以便布局位于 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>
已解决:
我没有在 Page_three.xml 中添加 cardview
,而是将其包裹在 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>
好的,在 LinearLayout 下的 cardview 中有这个复选框列表。并且我添加了一个滚动视图,因为它无法容纳所有视图,我想稍后添加一个滑块。但问题是我无法让它一直向上滚动,如图所示 below.I 已经尝试了一些在线论坛和某些网站上提供的解决方案,例如 android:fillViewport="true"
,但是 none 其中似乎有效。
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>
您项目的 styles configuration
一定有问题,因为您的布局低于 statusbar
。
在您的布局的根视图中使用 android:fitsSystemWindows="true"
,ScrollView
您的情况。
已编辑
您必须将 android:paddingBottom="?attr/actionBarSize"
(BottomNavigationView
的任何尺寸)添加到您的 ScrollView
,以便布局位于 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>
已解决:
我没有在 Page_three.xml 中添加 cardview
,而是将其包裹在 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>