0

I have extended FrameLayout class for making slide-in slide-out animation on fragment transition. I want to get xFraction value programmatically.

<?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:orientation="vertical" >

    <ImageView
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:src="@+drawable/logo" />

    <com.example.helpers.CustomFrameLayout
        android:id="@+id/fragment"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />

</RelativeLayout>

CustomFrameLayout looks like

public class CustomFrameLayout extends FrameLayout {


    public CustomFrameLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

    public CustomFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public CustomFrameLayout(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public float getXFraction() {
        return getX() / getWidth();
    }

    public void setXFraction(float xFraction) {
        final int width = getWidth();
        setX((width > 0) ? (xFraction * width) : -9999);
    }
}

An exception is thrown when animation is starting after button click:

Can't find native method using JNI, use reflectionjava.lang.NoSuchMethodError: no method with name='setXFraction' signature='(F)V' in class Landroid/widget/RelativeLayout;
02-17 13:57:33.369: E/PropertyValuesHolder(12223): Couldn't find setter/getter for property xFraction with value type float

Animate the transition between fragments - i got my idea from there. But it doesn't work. Help me please

Community
  • 1
  • 1
  • http://stackoverflow.com/questions/19372436/doing-a-push-fragment-animation?answertab=active#tab-top - i have found the answer here. – user2918962 Feb 18 '14 at 10:56

2 Answers2

0

It seems that you are trying to call method: setXFraction() on the parent RelativeLayout instead on your com.example.helpers.CustomFrameLayout.

You should get reference to your CustomFrameLayout like this (assuming you already have reference to your parent layout named parentRelativeLayout):

CustomFrameLayout customFrameLayout = (CustomFrameLayout) parentRelativeLayout.findViewById(R.id.fragment);

Now you can call setXFraction() on the proper reference e.g.:

customFrameLayout.setXFraction(25.4);
petrsyn
  • 5,054
  • 3
  • 45
  • 48
  • public void onClick(View v) { parentAct.setTransaction(getFragmentManager() .beginTransaction()); parentAct.getTransaction().setCustomAnimations( R.anim.slide_from_right_to_screen, R.anim.slide_from_screen_to_left); parentAct.getTransaction().replace(R.id.fragment, parentAct.getNativeLoginFr()); parentAct.getTransaction().commit(); } - so i don't call this method, it should work itself – user2918962 Feb 17 '14 at 11:01
  • my slide_from_right_to_screen.xml content is – user2918962 Feb 17 '14 at 11:04
0

Whatever view you are trying to animate should have setXFraction method.

If you are inflating this entire xml, it would check for setXFraction in your relative layout.

I guess getNativeLoginFr is give your view and it is inflating the entire xml..

You need to only inflate that FrameLayout for your animation to work.

Priya
  • 489
  • 1
  • 10
  • 20