我需要使用自定义动画制作2个屏幕,如下所示:
Screen 1 Screen 2 ----------------------------- ------------------------------ | | | | | | | | | | | | | | | | | | | List 1 | List2 | ---------> | List 3 | List 4 | | (75% width) |(25% wid)| |(25%wid)| (75% width) | | | | | | | | | | | | | ----------------------------- ------------------------------
我已将每个列表放在LinearLayout
中,并且所有LinearLayout
都包含在根LinearLayout
中。在List1
上检测到从左到右滑动后,我执行此操作
AnimationSet set = new AnimationSet(true);
Animation animation = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.75f,
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
animation.setDuration(500);
animation.setZAdjustment(Animation.ZORDER_TOP); // Keep the viewgroup on which this animation applies at the top.
set.addAnimation(animation);
LayoutAnimationController controller =
new LayoutAnimationController(set, 0.0f);
screenOne_layoutOne.setLayoutAnimation(controller);
screenOne_layoutOne.startLayoutAnimation();
我能够获得动画,但screenOne_layoutOne
(包含List 1
的布局)并不能保持最佳状态。动画低于List2
。
谁能告诉我问题出在哪里?
提前致谢。
答案 0 :(得分:0)
对于那些感兴趣的人,我能够通过将两个屏幕的布局放在一个布局文件中并更改布局/视图的visibility
来解决这个问题。使用的布局文件是
<LinearLayout android:id="@+id/featured_view_container"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible" >
<ListView android:id = "@+id/featured_list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" />
<ImageView android:layout_height = "match_parent"
android:layout_width="wrap_content"
android:src="@drawable/seperator"/>
<LinearLayout android:id = "@+id/categories"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<!-- Layout for the screen 2-->
<LinearLayout android:id="@+id/category_view_container"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone" >
<LinearLayout android:id = "@+id/subcategories"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageView android:layout_height = "match_parent"
android:layout_width="wrap_content"
android:src="@drawable/seperator"/>
<ListView android:id = "@+id/subcategory_list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" />
</LinearLayout>
当我在list1(anim
)上应用动画(featured_list
)时,如果我这样做,它就会保持在最顶层
anim.setZAdjustment(Animation.ZORDER_TOP)