Sal*_*lu3 67 android android-animation android-fragments
我正在尝试使用自定义动画来处理我的片段.
我已经按照在线教程,但我得到了以下错误:
java.lang.RuntimeException:未知的动画师名称:translate
动画的XML如下:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="0"
android:duration="300" />
</set>
Run Code Online (Sandbox Code Playgroud)
Java文件如下所示:
public void goCategory(View v) {
FragmentTransaction ft = fm.beginTransaction();
ft.setCustomAnimations(R.animator.anim_in_left, R.animator.anim_out_left);
ft.show(fragment);
ft.commit();
}
Run Code Online (Sandbox Code Playgroud)
我无法理解其他线程中的解决方案.如果有人能为我愚蠢,我真的很感激.
min*_*vac 114
可能你正在混合两个apis.有两种情况:
如果定位低于3.0 或使用支持v4片段:你必须使用旧的动画api,即你正在使用的那个(它们进入anim /,并且是R.anim.thing)
如果你的目标是3.0以上并使用原生片段:你必须使用新的动画apis,即ObjectAnimators(它们进入animator /并且是R.animator.thing).
小智 107
它不起作用,你应该使用对象动画师
动画/ slide_in_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:propertyName="x"
android:valueFrom="1000"
android:valueTo="0"
android:valueType="floatType" />
</set>
Run Code Online (Sandbox Code Playgroud)
动画/ slide_out_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:propertyName="x"
android:valueFrom="0"
android:valueTo="-1000"
android:valueType="floatType" />
</set>
Run Code Online (Sandbox Code Playgroud)
类子类别
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
// return super.onCreateView(inflater, container, savedInstanceState);
View view = (ViewGroup) inflater.inflate(R.layout.product_frame, null);
getFragmentManager().beginTransaction()
.replace(R.id.sub_header, new Sub_Header()).commit();
getFragmentManager()
.beginTransaction()
.setCustomAnimations(R.animator.slide_in_left,
R.animator.slide_out_right, 0, 0)
.replace(R.id.product_frame, new Sub_Catagory_Grid()).commit();
view.getWidth();
return view;
}
Run Code Online (Sandbox Code Playgroud)