我有一个Activity包含ViewPager,这个ViewPager中的第一个Fragment包含ListView,当我点击任何Item时它用选定的一个替换这个Fragment,我使用setCurrentItem(selectedItem,true)//for smooth scroll
ViewPager滑过所有Fragments,然后选择Fragment我想让它滑到选中的Fragment在我试图使用的所有片段PageTransfrom.transformPage上
@Override
public void transformPage(View page, float position) {
int currentItem = viewPager.getCurrentItem();
if (currentItem != selectedItem)
page.setVisibility(View.GONE);
}
Run Code Online (Sandbox Code Playgroud)
但没有运气
如何在两个Activity之间创建动画,就像在Android中的As Screen一样
我试图将动画添加到从底部单击按钮时出现的片段中。
片段布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:background="@color/wallet_holo_blue_light"
android:layout_gravity="center"
android:text="This is a fragmentt layout"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
滑动up.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime">
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime"
android:fromYDelta="50.0%p"
android:interpolator="@android:anim/decelerate_interpolator"
android:toYDelta="30" />
</set>
Run Code Online (Sandbox Code Playgroud)
在这里调用:
public void onClick(View view) {
if(view == button ){
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
FragmentOnMap hello = new FragmentOnMap();
fragmentTransaction.add(R.id.fragment_container, hello, "HELLO");
fragmentTransaction.setCustomAnimations(R.animator.slide_up,0);
fragmentTransaction.commit();
}
}
Run Code Online (Sandbox Code Playgroud)
Android Fragments和动画显示了如何上下滑动,我只是将片段动画化。因此,我的问题是setcustomanimation()函数的第二个参数
我尝试fragmentTransaction.setCustomAnimations()在提交前使用,但没有帮助。
它确实出现在底部,但是没有过渡效果。任何指导都是有用的。谢谢
如何通过下一个片段进行推送当前片段的动画
这是我想要的动画:

我当前的动画代码只是将第一个片段与第二个片段重叠,它没有像图片中那样推动它
这是代码:
result_list.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> av, final View view,
final int i, long i2) {
result_list.setEnabled(false);
view.animate().setDuration(300).translationX(widthListView).alpha(0).
withEndAction(new Runnable() {
@Override
public void run() {
//setResult(Activity.RESULT_OK,new Intent().putExtra("bussStopCode", data.get(i).getStopCode()).putExtra("bussStopName", data.get(i).getStopName()));
////int get 1
//data.remove(i);
int temporaryInteger = i;
listLastPostion = temporaryInteger;
//customAdapter.notifyDataSetChanged();
//view.setTranslationX(0);
Log.d("data",conreq.getCollectedData().getBusRouteSetData().get(temporaryInteger - 1).getRouteHeading());
Bundle bundle = new Bundle();
bundle.putString("busdestination", conreq.getCollectedData().getBusRouteSetData().get(temporaryInteger-1).getRouteHeading());
bundle.putString("busnumber", conreq.getCollectedData().getBusRouteSetData().get(temporaryInteger-1).getRouteNo());
Fragment fragment = new FragmentNextTripForStop();
fragment.setArguments(bundle);
FragmentTransaction fragmentManager = getFragmentManager().beginTransaction();
fragmentManager.setCustomAnimations(R.anim.right_left_anim_x_left,R.anim.right_left_anim_x_right,R.anim.left_right_anim_x_left,R.anim.left_right_anim_x_right);
fragmentManager.add(R.id.fragment_searched_data_xml, fragment).addToBackStack(null).commit();
// finish();
//overridePendingTransition(R.anim.right_left_anim_x_left,R.anim.right_left_anim_x_right);
}
});
}});
Run Code Online (Sandbox Code Playgroud)