当MapView进行缩放输入/输出时,碎片会一直返回到默认位置

时间:2012-07-04 13:55:00

标签: android

我有一个显示3个片段的活动,MapActivityListActivity和(正常)DetailsActivityListActivityDetailsActivity放置在MapActivity上。

有一个功能可以使用动画隐藏ListActivity和DetailsActivity,onAnimationEnd()我为隐藏的Activity设置了新的布局。

我面临的问题是,每当ListActivity或DetailsActivity中的一个隐藏(图片状态2),然后我捏住MapActivity上的屏幕来缩放地图,它总是会回来到默认视图(图片状态1)。已关闭的活动将再次自动打开。

当我捏MapActivity时,有人知道如何防止隐藏的片段再次进入第一个状态吗?

这是我隐藏DetailsActivity()的函数示例:

public void hideDetailview() {
        final Animation close = AnimationUtils.loadAnimation(this, R.anim.close);
        close.setFillEnabled(true);
        close.setAnimationListener(closeDetailAnimationListener);
        fragment_detail.startAnimation(close);

        Toast.makeText(MainFragmentActivity.this,WWHApplication.getDrawer(), Toast.LENGTH_SHORT).show();
    }

    private AnimationListener closeDetailAnimationListener = new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {


            int newLeft = -330;
            fragment_detail.layout(newLeft, 
                    fragment_detail.getTop(), 
                                newLeft + fragment_detail.getMeasuredWidth(), 
                                fragment_detail.getTop() + fragment_detail.getMeasuredHeight());

        }
    };

这是xml布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.wwh"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <fragment
        android:id="@+id/my_map_fragment1"
        android:name="com.wwh.fragments.MyMapFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <!-- Preview: layout=@layout/my_map_fragment -->
    </fragment>

    <RelativeLayout
        android:id="@+id/fragment_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="55dp"
        android:orientation="horizontal" >

        <LinearLayout
            android:id="@+id/detail_layout"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

            <fragment
                android:id="@+id/my_detail_fragment"
                android:name="com.wwh.fragments.DetailFragment"
                android:layout_width="380dp"
                android:layout_height="fill_parent" />

            <LinearLayout
                android:id="@+id/border_detail"
                android:layout_width="1dp"
                android:layout_height="fill_parent"
                android:background="@drawable/border"
                android:orientation="vertical" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/list_layout"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_toRightOf="@+id/detail_layout"
            android:orientation="horizontal" >

            <fragment
                android:id="@+id/my_list_fragment"
                android:name="com.wwh.fragments.MyListFragment"
                android:layout_width="380dp"
                android:layout_height="fill_parent"
                android:background="@drawable/border"
                android:shadowColor="#000000"
                android:shadowDx="1.2"
                android:shadowDy="12"
                android:shadowRadius="12" />

            <LinearLayout
                android:id="@+id/border_list"
                android:layout_width="1dp"
                android:layout_height="fill_parent"
                android:background="@drawable/border"
                android:orientation="vertical" />

            <ImageView
                android:id="@+id/shadow_vertical"
                android:layout_width="2dp"
                android:layout_height="fill_parent"
                android:layout_marginTop="53dp"
                android:background="@drawable/shadow_vertical" />
        </LinearLayout>
    </RelativeLayout>

</RelativeLayout>

The normal default state, all fragments are opened

Second state, fragments are closed

1 个答案:

答案 0 :(得分:1)

您可能忘记更新其他片段的布局了吗?或者,您可能错误地计算了新布局?

我之所以这么说,因为旧的Android版本的动画很棘手,因为它们并没有真正改变视图的布局。所以也许当动画结束时,你实际上会碰到一些你认为自己没有感动过的东西。

请提供更多代码。也许它可以帮助我们理解它为什么会发生。

顺便说一下,请重命名片段类。他们不是活动,所以为什么要活动&#34;在他们的名字?