gpt4 book ai didi

Android:animateLayoutChanges 无法与 CoordinatorLayout 一起正常工作

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:45:58 25 4
gpt4 key购买 nike

我一直在尝试在我的 Android 应用程序中使用协调器布局。我在协调器布局中有一个应用栏布局和一个嵌套 ScrollView 。在我的嵌套 ScrollView 中,我有一个线性布局,其中 animateLayoutChanges 为真。

我的问题是,当线性布局的高度因项目可见性而增加时,线性布局会在 Appbar 布局下。只有在单击屏幕或滚动之后,才会出现适当的滚动效果。

我创建了一个简单的应用程序来展示这个问题。下面是布局。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:animateLayoutChanges="true"
tools:context="testapp.test.MainActivity">

<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:animateLayoutChanges="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:animateLayoutChanges="true"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/AppTheme.PopupOverlay">

</android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:animateLayoutChanges="true">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show"
android:id="@+id/test_Button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hide"
android:id="@+id/test_Button2"/>
<TextView
android:id="@+id/test_tv"
android:layout_width="match_parent"
android:layout_height="300dp"
android:visibility="gone"
android:background="@color/colorAccent"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

在此单击显示按钮时,我使 Textview 可见。请查看图片以了解我的问题。

图 1-初始状态。

图 2- 这就是问题所在。我点击了显示。现在,由于动 Canvas 局更改的动画,线性布局已移至应用栏布局下。如您所见,显示按钮已移至应用栏下方。

图 3- 现在当我触摸屏幕或滚动时,滚动变得正常。

请帮忙。几天来我一直在努力解决这个问题。谢谢。

Initial State.

Here is the problem. I have clicked Show. Now the Linear layout has moved under App Bar Layout due to animation. Now when I touch screen or scroll, the scrolling becomes proper.

最佳答案

我遇到了同样的问题:包含 LinearLayout 且 animateLayoutChanges 设置为 true 的 NestedScrollView 导致内容出现滚动问题。在我的例子中,内容在 appBarLayout 下滑动。

此错误在此处记录为 issue 180504 .从支持库 23.2.0 开始,这似乎已得到修复,这意味着更新到此应该可以解决问题:

ext {
supportLibraryVersion = "23.2.0"
}

dependencies {
...

// this is the primary dependency for coordinator layout
// but, of course, update all that depend on the support library
// note: the design library depends on the Support v4 and AppCompat Support Libraries
// those will be included automatically when you add the Design library dependency
compile "com.android.support:design:$supportLibraryVersion"

...
}

关于Android:animateLayoutChanges 无法与 CoordinatorLayout 一起正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36094499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com