我已經擴展FrameLayout類用於在片段轉換中製作幻燈片滑出動畫。我想以編程方式獲得xFraction值。Android。擴展FrameLayout。找不到屬性的setter/getter xFraction異常
<?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看起來像
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);
}
}
當動畫按鈕,點擊後開始拋出一個異常:
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 - 我有我的想法來自那裏。但它不起作用。請幫助我
http://stackoverflow.com/questions/19372436/doing-a-push-fragment-animation?answertab=active#tab-top - 我在這裏找到了答案。 – user2918962