Android 如何阻止此进度条与工具栏一起滚动?
有没有办法阻止此Android 如何阻止此进度条与工具栏一起滚动?,android,android-layout,Android,Android Layout,有没有办法阻止此ProgressBar与工具栏一起上下滚动?现在我有两个工具栏,当RecyclerView中有项目时,应该上下滚动,问题是当没有任何结果显示时,滚动行为会影响工具栏下方的布局。看一看: 不用说,在任何情况下都不应该滚动progressbar。以下是布局: activity\u base.xml <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/
ProgressBar
与工具栏一起上下滚动?现在我有两个工具栏,当RecyclerView
中有项目时,应该上下滚动,问题是当没有任何结果显示时,滚动行为会影响工具栏下方的布局。看一看:
不用说,在任何情况下都不应该滚动progressbar。以下是布局:
activity\u base.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="64dp"
android:minHeight="64dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarBottom"
android:layout_width="match_parent"
android:layout_height="64dp"
android:minHeight="64dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_gravity="bottom"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:id="@+id/spinner_sites"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Spinner
android:id="@+id/spinner_sort_field"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Spinner
android:id="@+id/spinner_sort_order"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/activity_masterdetail"/>
<View
android:id="@+id/view_search_tint"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.0"
android:background="#88000000"
android:elevation="2dp"
android:layerType="hardware"
android:visibility="gone" />
<org.cryse.widget.persistentsearch.PersistentSearchView
android:id="@+id/searchview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:elevation="4dp"
app:persistentSV_logoString="@string/app_name"
app:persistentSV_searchTextColor="?android:textColorPrimary"
app:persistentSV_editTextColor="?android:textColorPrimary"
app:persistentSV_editHintText="Search"
app:persistentSV_editHintTextColor="?android:textColorHint"
app:persistentSV_displayMode="toolbar"
app:persistentSV_homeButtonMode="burger"
app:persistentSV_searchCardElevation="2dp"
app:persistentSV_customToolbarHeight="64dp"
app:layout_behavior=".ScrollingSearchViewBehavior"/>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"/>
<!-- include pogress bar-->
<include
android:id="@+id/progress_bar"
layout="@layout/progress_bar"
android:visibility="gone" />
</RelativeLayout>
fragment\u list.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="64dp"
android:minHeight="64dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarBottom"
android:layout_width="match_parent"
android:layout_height="64dp"
android:minHeight="64dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_gravity="bottom"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:id="@+id/spinner_sites"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Spinner
android:id="@+id/spinner_sort_field"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Spinner
android:id="@+id/spinner_sort_order"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/activity_masterdetail"/>
<View
android:id="@+id/view_search_tint"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.0"
android:background="#88000000"
android:elevation="2dp"
android:layerType="hardware"
android:visibility="gone" />
<org.cryse.widget.persistentsearch.PersistentSearchView
android:id="@+id/searchview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:elevation="4dp"
app:persistentSV_logoString="@string/app_name"
app:persistentSV_searchTextColor="?android:textColorPrimary"
app:persistentSV_editTextColor="?android:textColorPrimary"
app:persistentSV_editHintText="Search"
app:persistentSV_editHintTextColor="?android:textColorHint"
app:persistentSV_displayMode="toolbar"
app:persistentSV_homeButtonMode="burger"
app:persistentSV_searchCardElevation="2dp"
app:persistentSV_customToolbarHeight="64dp"
app:layout_behavior=".ScrollingSearchViewBehavior"/>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"/>
<!-- include pogress bar-->
<include
android:id="@+id/progress_bar"
layout="@layout/progress_bar"
android:visibility="gone" />
</RelativeLayout>
正如您所看到的,除了SearchView之外,布局非常标准,所以我不知道为什么会出现这个问题。我发现从activity\u fragment.xml
中删除app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
可以阻止问题的发生,但是RecyclerView
没有与工具栏对齐,结果显示在整个屏幕上,覆盖了工具栏和所有页面。这当然不是我想要的
将
RecyclerView
的可见性标记为“消失”也会停止滚动ProgressBar
,但同样的,它没有集中化,这意味着问题仍然存在,只是我无法滚动屏幕。在几乎每个容器中设置android:fitsystemwindows=“true”属性也不起作用。我尝试过调整几乎所有我能想到的布局属性,但没有运气,任何帮助都将不胜感激。似乎我必须发布我自己问题的答案,这更像是一种解决方法,但它确实有效。我将等待一个“实际”的答案,并在发布时标记为这样
您需要做的是从activity\u fragment.xml
中删除app:layou\u behavior=“@string/appbar\u scrolling\u view\u behavior”
属性,并在ProgressBar
被setVisibility(view.GONE)
隐藏后以编程方式添加它。您还必须确保在再次显示ProgressBar
时将其删除。这通常可以在Asynctask的onPostExecute()
和onPreExecute()方法中完成。为此,您需要保留对@+id/fragment\u列表的引用。代码如下:
View parent;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// keeping a reference to the @+id/fragment_list fragment
parent = container;
// other code
task = new SearchResultsTask();
task.execute();
return view;
}
在SearchResultsTask
AsyncTask
上:
@Override
protected void onPostExecute(List s) {
super.onPostExecute(s);
adapter.adds(s);
progressBar.setVisibility(View.GONE);
CoordinatorLayout.LayoutParams params =
(CoordinatorLayout.LayoutParams) parent.getLayoutParams();
// adding the behaviour programatically
params.setBehavior(new AppBarLayout.ScrollingViewBehavior());
parent.requestLayout();
rvList.setVisibility(View.VISIBLE);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
CoordinatorLayout.LayoutParams params =
(CoordinatorLayout.LayoutParams) parent.getLayoutParams();
// removing the behaviour
params.setBehavior(null);
parent.requestLayout();
progressBar.setVisibility(View.VISIBLE);
}
看来我必须对我自己的问题发表一个答案,这更像是一个解决办法,但确实有效。我将等待一个“实际”的答案,并在发布时标记为这样
您需要做的是从activity\u fragment.xml
中删除app:layou\u behavior=“@string/appbar\u scrolling\u view\u behavior”
属性,并在ProgressBar
被setVisibility(view.GONE)
隐藏后以编程方式添加它。您还必须确保在再次显示ProgressBar
时将其删除。这通常可以在Asynctask的onPostExecute()
和onPreExecute()方法中完成。为此,您需要保留对@+id/fragment\u列表的引用。代码如下:
View parent;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// keeping a reference to the @+id/fragment_list fragment
parent = container;
// other code
task = new SearchResultsTask();
task.execute();
return view;
}
在SearchResultsTask
AsyncTask
上:
@Override
protected void onPostExecute(List s) {
super.onPostExecute(s);
adapter.adds(s);
progressBar.setVisibility(View.GONE);
CoordinatorLayout.LayoutParams params =
(CoordinatorLayout.LayoutParams) parent.getLayoutParams();
// adding the behaviour programatically
params.setBehavior(new AppBarLayout.ScrollingViewBehavior());
parent.requestLayout();
rvList.setVisibility(View.VISIBLE);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
CoordinatorLayout.LayoutParams params =
(CoordinatorLayout.LayoutParams) parent.getLayoutParams();
// removing the behaviour
params.setBehavior(null);
parent.requestLayout();
progressBar.setVisibility(View.VISIBLE);
}
您是否尝试过将其包含在坐标布局之外
或将进度条包含在其相对布局之外
?如果您希望避免滚动(换句话说,“位于”RecyclerView的顶部),那么它不应该与RecyclerView的深度相同,它应该在活动中,从片段中,您可以使用Activity@Shark我已经考虑过了,但问题是我希望它集中在片段的布局中,因为在某些分辨率下,这将是一个双窗格布局,并且会有其他与之相关的progressbar(并集中在)另一个窗格中。就像平板电脑上的两个窗格Gmail应用程序一样。将progressbar包含在片段的根布局中就可以了,不是吗?不知何故,它确实需要“在上面”(Z轴方向)recyclerview可以实现您的目标。@Shark您是指activity_fragment.xml中的Shark?好吧,现在它就在recyclerview的上方,但由于某种原因,布局在屏幕底部有一些空白区域,您可以滚动……我尝试过在相关位置应用wrap_内容,但没有任何区别。您是否尝试过将其包含在协调布局
之外,或将进度条包含在其相对布局
之外?如果您希望避免滚动(换句话说,“在循环视图的顶部”),则其深度不应与循环视图的深度相同我想说的是,它应该在活动中,从片段中,您可以使用Activity@Shark我已经考虑过了,但问题是我希望它集中在片段的布局中,因为在某些分辨率下,这将是一个双窗格布局,并且会有其他与之相关的progressbar(并集中在)另一个窗格中。就像平板电脑上的两个窗格Gmail应用程序一样。将progressbar包含在片段的根布局中就可以了,不是吗?不知何故,它确实需要“在上面”(Z轴方向)recyclerview可以实现您的目标。@Shark您是指activity_fragment.xml中的Shark?好吧,现在它就在recyclerview的上方,但由于某种原因,布局在屏幕底部有一些空白区域,您可以滚动……我尝试过在相关位置应用wrap_内容,但没有任何区别。