【发布时间】:2017-07-25 15:27:42
【问题描述】:
我一直使用 Activity 进入/返回转换(使用像幻灯片和淡入淡出这样的 xml 转换来动画视图)并且总是工作,因为它非常简单。现在,在我的上一个项目中,即使使用虚拟活动(没有任何实际处理),我也遇到了问题,转换根本不起作用,所以经过数小时更改布局代码后,我发现责任是根 FrameLayout 中的android:background我设置了一些背景颜色的活动布局。当我删除此属性时,转换又恢复了工作。此外,如果我仅在活动主题中应用此属性,则转换将再次停止。
目前我的项目只是动画第二个只有这种布局结构的活动:
<FrameLayout 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:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView>
<RecyclerView>
</FrameLayout>
过渡确实从顶部滑入 ImageView 并从底部滑入 RecyclerView。但就像我说的那样。仅当根 FrameLayout 没有背景颜色时才有效。
你知道这是一个错误还是其他什么?
编辑:如果我使用丑陋的虚拟视图只是为了提供背景颜色,则转换工作:
<FrameLayout 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">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary" />
<ImageView>
<RecyclerView>
</FrameLayout>
编辑 2:如果我使用另一个根 ViewGroup(如 LinearLayout)而不是 FrameLayout,也会出现同样的问题。
【问题讨论】:
-
你确定你使用的是有效的颜色或有效的drawable吗?
-
是的,我使用主应用主题的 colorPrimary 只是为了测试 pourposes,它在应用中显示,但过渡不起作用。
-
你能提供一段代码如何设置这个颜色吗?
-
我已经编辑了我的问题。
-
"FrameLayout 被设计为在屏幕上屏蔽一个区域以显示单个项目"。从框架布局中删除一项并重试。
标签: android android-layout android-animation