Android - Layout Animation не остается на вершине - PullRequest
0 голосов
/ 05 ноября 2011

Мне нужно сделать 2 экрана с пользовательской анимацией, как описано ниже:


          Screen 1                                    Screen 2
 -----------------------------              ------------------------------
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
|       List 1      |  List2  | ---------> | List 3 |      List 4         |
|   (75% width)     |(25% wid)|            |(25%wid)|   (75% width)       |
|                   |         |            |        |                     |
|                   |         |            |        |                     |
 -----------------------------              ------------------------------

  • Пользователь делает длинное касание элемента в Списке 1 и скользит слева направо.
  • Вид, содержащий Список 1, перемещается слева направо (до конца экрана) и исчезает. Отображается экран 2.

Я поместил каждый из списков в LinearLayout, и все LinearLayout s содержатся в корне LinearLayout. После обнаружения пролистывания слева направо на List1, я делаю это

</p> <pre> 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(); </pre> <p>

Мне удалось получить анимацию, но screenOne_layoutOne (макет, содержащий List 1) не остается на вершине. Анимация идет ниже List2.

Может кто-нибудь сказать мне, где проблема?

Заранее спасибо.

1 Ответ

0 голосов
/ 15 ноября 2011

Для тех из вас, кому это интересно, я смог решить эту проблему, поместив макеты обоих экранов в один файл макета и изменив 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>

, когда я применил анимацию (anim) к списку 1 (featured_list), он останется сверху, если яделать

                    anim.setZAdjustment(Animation.ZORDER_TOP)
...