Thursday 15 January 2015

android - Fragment Transition Animation using Object Animator not working -



android - Fragment Transition Animation using Object Animator not working -

i want isn't duplicate, question hasn't been addressed on stack overflow

i have multiple fragments in application user navigates through. had back upwards library in code have since removed it, when using was animating fragments <translate> . have changed works fine if hard code in values , from. app used on different screen densities can't this. after research , tutorials created custom framelayout follows:

public class customframelayout extends framelayout{ public customframelayout(context context, attributeset attrs) { super(context, attrs); } public float getxfraction() { homecoming getx() / getwidth(); // todo: guard divide-by-zero } public void setxfraction(float xfraction) { // todo: cache width final int width = getwidth(); setx((width > 0) ? (xfraction * width) : -9999); } }

my animation xml is:

<?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:interpolator="@android:anim/linear_interpolator" android:valuefrom="1.0" android:valueto="0" android:propertyname="xfraction" android:duration="@android:integer/config_mediumanimtime" /> </set>

and main activity layout is:

<com.axn.test.app.custom.customframelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/container" android:gravity="top" android:layout_width="match_parent" android:layout_height="match_parent" />

i have code set custom animations:

fragmenttransaction ft = getactivity().getfragmentmanager().begintransaction(); ft.setcustomanimations(r.animator.fragment_slide_in_right, r.animator.fragment_slide_in_right, r.animator.fragment_slide_in_right, r.animator.fragment_slide_out_right);

the problem when alter fragments there no animation , next in console:

w/propertyvaluesholder﹕ method setxfraction() type float not found on target class class android.widget.relativelayout

so if has come across in past or knows how prepare issue i'd appreciate it. in customframelayout setxfraction(float xfraction) , getxfraction() never called i'm not sure go here...all input appreciated

**edit ==== fragment layout ===== **

<?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:background="@drawable/background" > <linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <relativelayout android:layout_margintop="20dp" android:layout_marginleft="20dp" android:id="@+id/show1" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true"> <imageview android:id="@+id/poster1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/poster1"/> <relativelayout android:id="@+id/poster1details" android:background="@drawable/reflection1" android:layout_below="@+id/poster1" android:layout_width="wrap_content" android:layout_height="wrap_content"> <textview android:id="@+id/poster1text" android:layout_centerhorizontal="true" android:textcolor="@color/white" android:textappearance="?android:attr/textappearancemedium" android:text="@string/poster1title" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/poster1text" android:layout_centerhorizontal="true" android:textcolor="@color/white" android:textappearance="?android:attr/textappearancesmall" android:text="@string/episode1"/> </relativelayout> </relativelayout> <relativelayout android:id="@+id/show2" android:layout_weight="1" android:layout_marginright="10dp" android:layout_margintop="20dp" android:layout_marginleft="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true"> <imageview android:id="@+id/poster2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/poster2"/> <relativelayout android:id="@+id/poster2details" android:background="@drawable/reflection2" android:layout_below="@+id/poster2" android:layout_width="wrap_content" android:layout_height="wrap_content"> <textview android:id="@+id/poster2text" android:layout_centerhorizontal="true" android:textcolor="@color/white" android:textappearance="?android:attr/textappearancemedium" android:text="@string/poster2title" android:gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/poster2text" android:layout_centerhorizontal="true" android:textcolor="@color/white" android:textappearance="?android:attr/textappearancesmall" android:text="@string/episode1"/> </relativelayout> </relativelayout> </linearlayout> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true"> <imageview android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/logos_backgrounds" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/presents" android:textcolor="@color/white" android:layout_centerhorizontal="true" android:layout_margintop="10dp" /> </relativelayout> </relativelayout>

the problem trying animate fragment. not activity. have add together customframelayout on fragment setting animations to. 1 time transaction takes place transaction animate values on fragment's parent , not activity's. that's why you're getting method setxfraction() type float not found on target class class android.widget.relativelayout. because parent of fragment relativelayout , doesn't have setxfraction method.

still left rest of anwser bellow because might help others.

in_from_left.xml

<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" />

in_from_right.xml

<?xml version="1.0" encoding="utf-8"?> <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" />

and transaction looks this:

fragmenttransaction transaction = getfragmentmanager().begintransaction(); transaction.setcustomanimations(r.anim.in_from_left, r.anim.in_from_right, r.anim.in_from_left, r.anim.in_from_right); transaction.add(r.id.container,myfragment,"tag"); transaction.commit();

android android-fragments fragmenttransaction objectanimator

No comments:

Post a Comment