Android FragmentTransaction:如何生成覆盖幻灯片并将现有碎片向左移动
我试着做以下几点。创建一个新的片段B(菜单),从右边滑入,我想将已经显示的片段a移到左边(不要隐藏或替换!)。 我从片段B获得了正确的交易,但是片段A根本没有改变他的位置。看起来,我的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
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>
FragementManager
中,我可以隐藏它,但这不是我的目标
Fragment fragmentA = fragmentManager.findFragmentById(R.id.map_screen);
ft.hide(fragmentA); //hide FragmentA
我做错了什么
一些注意事项:
- 我正在使用支持库(android.Support.v4.app.FragmentManager…),但在API 17上进行测试
- 如前所述,我没有专门向
声明FragmentA(尝试过,但它说FragmentA已经存在)FragmentManager
- 片段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);
}