- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
如果在 Toolbar 的 app:layout_scrollFlags
值 scroll
处移除,则内容将移动到顶部。看截图
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<!--region Content-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!--region EmptyView-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/titleView"
fontPath="@string/font_semibold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:padding="8dp"
android:textColor="#9b9b9b"
android:textSize="16sp"
tools:ignore="MissingPrefix"
tools:text="@string/error_view_internet_connection_title"/>
<TextView
android:id="@+id/messageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:gravity="center"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:textColor="#9b9b9b"
android:textSize="14sp"
tools:ignore="MissingPrefix"
tools:text="@string/error_view_internet_connection_message"
/>
</LinearLayout>
<!--endregion-->
<!--region List-->
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbarSize="2dp"
android:scrollbars="vertical"
android:visibility="gone"
tools:visibility="visible"/>
</android.support.v4.widget.SwipeRefreshLayout>
<!--endregion-->
</LinearLayout>
<!--endregion-->
<!--region Toolbar-->
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@android:color/transparent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="0dp"
app:layout_behavior="@string/appbar_layout_behavior"
app:layout_collapseMode="pin">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="?android:attr/toolbarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#636363"
android:minHeight="?android:attr/actionBarSize"
app:elevation="0dp"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/ToolbarStyle"
app:theme="@style/ToolbarStyle"
tools:ignore="NewApi"/>
</android.support.design.widget.AppBarLayout>
<!--endregion-->
</android.support.design.widget.CoordinatorLayout>
<!--region BottomNavigation-->
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
android:id="@+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:accentColor="#111232"
app:inactiveColor="#111232"
app:titleState="always_hide"/>
<!--endregion-->
</LinearLayout>
我通过 func 删除了标志,然后在 UI 中它在摇晃:
public void setToolbarCollapsible(boolean collapsible) {
int defaultFlags =
AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP
| AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS
| AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL;
int none = 0;
// //remove from toolbar
Toolbar toolbar = getToolbar();
if (toolbar == null) return;
AppBarLayout.LayoutParams toolbarLayoutParams = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
toolbarLayoutParams.setScrollFlags(collapsible ? defaultFlags : none);
toolbar.setLayoutParams(toolbarLayoutParams);
}
最佳答案
If remove at
app:layout_scrollFlags
valuescroll
in Toolbar , then content is moving to top.
内容向上移动是因为包裹 TextView
的 LinearLayout
的高度在变化。因此,在 LinearLayout
上指定的 android:gravity="center"
会计算不同的垂直中心。
以下布局是用于演示目的的布局的简化 View 。
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_light"
android:gravity="center"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:id="@+id/titleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/error_view_internet_connection_title"
android:textSize="16sp" />
</LinearLayout>
<android.support.design.widget.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="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:title="Toolbar" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
这是此布局的布局检查器 View ,显示设置和不设置滚动标志的 LinearLayout
的高度。
在没有设置滚动标志的情况下,包裹 TextViews
的 LinearLayout
的高度小于 Toolbar
的高度。这是有道理的,因为 LinearLayout
是 match_parent
它必须适合。设置滚动标志后,LinearLayout
可以更高,因为它可以滚动并且不必适合屏幕。事实上,它与屏幕一样高,但移到了工具栏下方。
您可以快速测试是否是这种情况,但将 android:gravity="center"
替换为上边距。
I remove the flag by func, and after that in UI it is shaking
我想我以前见过这种行为,但我不记得它的原因。由于 CoordinatorLayout
是如此动态,它可能是由于某些布局歧义导致的布局中的某种振荡。然而,这只不过是猜测。如果稍微清理一下布局并考虑为什么要操纵滚动标志(是否有其他方法?),您可能能够解决问题。
除此之外,演示抖动问题的小型可运行项目可能对发布有帮助。
关于xml - 为什么内容在删除 scrollFlags `scroll` 后被拖动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53478765/
我正在尝试使用 CoordinatorLayout 和 AppBarLayout 构建以下布局: | View 1(页眉)| | View 2 ----------| |回收站 View --- |
场景: 当其中一个toolbar消失时,第二个toolbar会适配第一个toolbar的scrollFlag , 而不是它自己的 scrollFlag! 注意: 只有当其中一个工具栏消失时才会发生奇怪
我正在尝试了解 CollapsingToolbarLayout,它有一些值设置为 scrollFlags 以控制其中的 View 如何折叠。任何人都可以清楚地划分这些标志之间的区别: 滚动 总是进入
如果在 Toolbar 的 app:layout_scrollFlags 值 scroll 处移除,则内容将移动到顶部。看截图 这是我的布局:
我是一名优秀的程序员,十分优秀!