CollapsingToolbarLayout禁用下拉扩展 [英] CollapsingToolbarLayout disable draw down expansion
问题描述
我有一个CollapsingToolbar,有条件地禁用了它.当用户在这种情况下加载视图时,它看起来就像一个普通的ToolBar对象.
I have a CollapsingToolbar that I have conditionally disabled. When the user loads the view under that condition, it just looks like a normal ToolBar object.
唯一奇怪的是,即使我希望并编写相反的代码,如果它们向下拖动(例如以拉动方式刷新样式动作),CollapsingToolbar也会扩展!
The only weird thing is that if they drag down, such as in a pull to refresh style action, the CollapsingToolbar expands, despite my wishes and code to the contrary!
这就是我所拥有的,注释掉的代码反映了我也尝试过的内容
Here is what I have, and the commented out code reflects what I have also tried
appBar.setExpanded(false);
appBar.setActivated(false);
/*CollapsingToolbarLayout.LayoutParams p = (CollapsingToolbarLayout.LayoutParams)toolbar.getLayoutParams();
p.setCollapseMode(CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_PIN);
toolbar.setLayoutParams(p);
CoordinatorLayout.LayoutParams appBarLayoutParams = (CoordinatorLayout.LayoutParams) appBar.getLayoutParams();
appBarLayoutParams.setBehavior(null);
appBar.setLayoutParams(appBarLayoutParams);*/
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams)appBar.getLayoutParams();
lp.height = (int) getResources().getDimension(R.dimen.app_bar_height);
我想禁用下拉扩展,但没有找到一种方法.此活动包含一个recyclerview,这是用户主要与之交互的对象.
I want to disable the drag down expansion, and I didn't see a way to do it. This activity contains a recyclerview and that is what users primarily interact with.
推荐答案
我与method密切相关.展开布局行为控件AppBarLayout.因此,您需要该小部件的更新扩展方法.基于 AppBarLayout文档.
I was closely with method. Expand layout behavior controls AppBarLayout. So you need update expand methods of that widget. Based on AppBarLayout Doc.
AppBarLayout appBarLayout;
//....
public void setExpandToolbar (boolean isEpand) {
if (isExpand) {
appBarLayout.setExpanded(true,true);
}
else {
appBarLayout.setExpanded(false,true);
}
}
让我知道有关此问题的信息.因为您可以通过其他解决方案控制扩展.例如,通过自定义布局参数.
Let me know, about this issue. Because you can control expand via other solution. For example, by custom layout params.
AppBarLayout.LayoutParams p = (AppBarLayout.LayoutParams)
toolbar.getLayoutParams();
p.setScrollFlags(0);
toolbar.setLayoutParams(p);
这篇关于CollapsingToolbarLayout禁用下拉扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!