0
我刚刚在我的项目中遇到了一个暂时似乎一直存在问题的障碍。NestedScrollView在CoordinatorLayout中隐藏底部小部件
我有一个CoordinatorLayout
它有一个AppBarLayout
和NestedScrollView
。我正在使用CollapsibleToobarLayout
,它工作得很好。问题是,NestedScrollView
不会上下滚动,因为它应该。在toolbar
崩溃后,它不再滚动,将隐藏的小部件隐藏起来。
我试过android:fillViewPort="true"
和android:layout_gravity="fill_vertical"
但没有改变。代码如下
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/MyMaterialTheme"
android:fitsSystemWindows="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="@+id/appBar"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/collapsingToolbar"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="10dp"
app:expandedTitleMarginEnd="10dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:background="@color/colorPrimary">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:background="@drawable/bgPicture"
app:layout_collapseMode="pin"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:titleTextAppearance="@style/Toolbar.TitleText"
android:layout_gravity="top"
app:layout_collapseMode="pin"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/custom_trash"
android:clickable="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="end"
android:id="@+id/deleteButton"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:fitsSystemWindows="true"
android:layout_gravity="fill_vertical"
android:background="@color/grey"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:id="@+id/tableLayout">
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_centerHorizontal="false"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:id="@+id/goalIdTextView"
android:visibility="gone"
/>
<ProgressBar
android:id="@+id/progress"
android:layout_width="match_parent"
android:indeterminate="false"
android:max="100"
android:progress="60"
android:progressDrawable="@drawable/circular_progress_bar"
android:layout_height="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="100%"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textAlignment="gravity"
android:layout_gravity="right"
android:id="@+id/progressText"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp">
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp">
<EditText
android:layout_weight="1"
android:id="@+id/goalTitle"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@android:drawable/editbox_background_normal"
android:paddingTop="14dp"
android:textCursorDrawable="@null"
android:paddingBottom="11dp"
android:hint="Goal Title"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp">
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="@string/deadline_text"
android:textStyle="bold"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp">
<EditText
android:id="@+id/dateEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ems="10"
android:layout_weight="1"
android:focusable="false"
android:inputType="date"
android:background="@android:drawable/editbox_background_normal"
android:paddingTop="14dp"
android:paddingBottom="11dp"
/>
<ImageButton
android:id="@+id/selectDate"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="0"
android:layout_toRightOf="@+id/date"
android:contentDescription="@string/select_date"
android:cropToPadding="true"
android:background="@drawable/calendar_icon"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp">
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="@string/tasks_label"
android:textStyle="bold"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:paddingTop="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:background="@android:drawable/editbox_background_normal"
android:layout_centerHorizontal="true" />
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/colorPrimary">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:textAllCaps="false"
android:id="@+id/updateButton"
android:textColor="#000"
android:onClick="updateGoal"
android:textAppearance="?android:textAppearanceLarge"
android:text="@string/submit"
/>
</TableRow>
</TableLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
ListView不显示在屏幕上后,它也不能滚动到视图中。 我已经看到这个应用程序在Whatsapp中实现。点击某个组会将您带到一个活动,其中一个配置文件图片显示在可折叠工具栏中,随后显示共享的图像,该组中的所有人员列表以及该页面底部的退出按钮。我尝试了几种方法来实现这一点,但我没有运气。
我已经使用了一个LinearLayout,然后甚至相对布局。我看到底部小部件的唯一方法是如果我删除NestedScrollView中的layout_behavior。在预览中,您实际上可以在屏幕外看到嵌套滚动视图的底部。在运行应用程序时,一旦可折叠工具栏折叠,嵌套滚动视图停止滚动。我的意思是,大多数视图滚动有告诉用户他已经达到了最后的方式(就像我的KitKat视图结尾的橙色),那么这个嵌套的滚动视图不会到达那个部分。我有什么意义吗? –
你有没有试过我的代码? –
是的,我有..可悲的是,没有运气 –