Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android FragmentTransaction:如何生成覆盖幻灯片并将现有碎片向左移动_Android_Android Widget_Android Fragments - Fatal编程技术网

Android FragmentTransaction:如何生成覆盖幻灯片并将现有碎片向左移动

Android FragmentTransaction:如何生成覆盖幻灯片并将现有碎片向左移动,android,android-widget,android-fragments,Android,Android Widget,Android Fragments,我试着做以下几点。创建一个新的片段B(菜单),从右边滑入,我想将已经显示的片段a移到左边(不要隐藏或替换!)。 我从片段B获得了正确的交易,但是片段A根本没有改变他的位置。看起来,我的FragmentManager不知道片段A的存在(片段A不是动态添加的,它是用XML定义的) 主屏幕布局-xml <RelativeLayout //... android:id="@+id/main_screen" tools:context=".MainActivity" &l

我试着做以下几点。创建一个新的片段B(菜单),从右边滑入,我想将已经显示的片段a移到左边(不要隐藏或替换!)。

我从片段B获得了正确的交易,但是片段A根本没有改变他的位置。看起来,我的
FragmentManager
不知道片段A的存在(片段A不是动态添加的,它是用XML定义的)

  • 主屏幕布局-xml

    <RelativeLayout //...
        android:id="@+id/main_screen"
        tools:context=".MainActivity" 
    
      <fragment
        android:id="@+id/map_screen"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        class="com.google.android.gms.maps.SupportMapFragment" >
      </fragment>
    
片段A存在于
FragementManager
中,我可以隐藏它,但这不是我的目标

Fragment fragmentA = fragmentManager.findFragmentById(R.id.map_screen);
ft.hide(fragmentA); //hide FragmentA
我做错了什么

一些注意事项:

  • 我正在使用支持库(android.Support.v4.app.FragmentManager…),但在API 17上进行测试
  • 如前所述,我没有专门向
    FragmentManager
    声明FragmentA(尝试过,但它说FragmentA已经存在)
  • 片段A(正如您在XML中看到的)是类
    SupportMapFragment
  • 动画XML正在工作,这就是为什么我没有发布它

我不确定这是否正是您想要的,但请查看此库。。。它允许在移动中心内容片段时从左侧或右侧滑入片段。

解决方案:

创建具有重叠片段的相对布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_screen"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity" >

    <RelativeLayout
        android:id="@+id/back_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <include layout="@layout/menu_fragment" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/front_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <fragment
            android:id="@+id/map_screen"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/map_screen_bottom_bar"
            class="com.google.android.gms.maps.SupportMapFragment" >
        </fragment>

我目前正在尝试归档与您相同的内容,但我不完全了解您的解决方案。我的B片段总是在动画完成后跳跃填充屏幕。有什么提示吗?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_screen"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity" >

    <RelativeLayout
        android:id="@+id/back_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <include layout="@layout/menu_fragment" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/front_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <fragment
            android:id="@+id/map_screen"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/map_screen_bottom_bar"
            class="com.google.android.gms.maps.SupportMapFragment" >
        </fragment>
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) {
                ((RelativeLayout) findViewById(R.id.front_frame)).animate()
                    .translationX(-1 * mScreenWidth);
            } else {
                TranslateAnimation slideOut = new TranslateAnimation(0, -1
                    * mScreenWidth, 0, 0);
                slideOut.setDuration(getResources().getInteger(
                    R.integer.animation_transistion_length_short));
                slideOut.setFillEnabled(true);

                slideOut.setAnimationListener(new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {}


                    @Override
                    public void onAnimationRepeat(Animation animation) {}


                    @Override
                    public void onAnimationEnd(Animation animation) {
                        RelativeLayout mView = (RelativeLayout) findViewById(R.id.front_frame);
                        int[] pos = { mView.getLeft() - mScreenWidth,
                            mView.getTop(), mView.getRight(),
                            mView.getBottom() };
                        mView.layout(pos[0], pos[1], pos[2], pos[3]);
                    }
                });

                ((RelativeLayout) findViewById(R.id.front_frame))
                    .startAnimation(slideOut);
            }