पर अनुवाद और ऑब्जेक्टएनिएटर बनाना एक टुकड़ा से दूसरे में स्लाइडिंग करते समय मैं 3 डी क्यूब रोटेशन प्रभाव बनाने की कोशिश कर रहा हूं। सबसे पहले मैं FragmentTransaction.setCustomAnimations(...)
के साथ कॉल करने के लिए एक अनुवाद प्रभाव (एक्सएमएल पर) का उपयोग कर रहा था और फिर, जब खंड को खोलना/बंद करना था, तो मैं रोटेशन बनाने के लिए कैमरा क्लैस के साथ खेल रहा था।एंड्रॉइड - एक ही एक्सएमएल फ़ाइल
यह ठीक काम कर रहा था, लेकिन ऐसा लगता है कि मुझे ऐसा करना है (मुझे क्यों नहीं पूछें) केवल इस एक्सएमएल फ़ाइल का उपयोग करके इस एनीमेशन का उपयोग करें। एक लंबी खोज के बाद मुझे पता चला कि मुझे रोटेशन बनाने के लिए ऑब्जेक्टएनिमीटर का उपयोग करना चाहिए।
Google नमूना का पालन किया और मैं फ्लिप एनीमेशन बनाने में कामयाब रहा। अब मुझे उन टुकड़ों का अनुवाद करने की आवश्यकता है जो उन्हें स्लाइडिंग और स्लाइडिंग कर रहे हैं। ऐसा लगता है कि मैं ऑब्जेक्टएनिमीटर का उपयोग नहीं कर सकता और उसी XML फ़ाइल पर प्रभाव का अनुवाद नहीं कर सकता। चूंकि यह त्रुटि प्रकट होती है:
java.lang.RuntimeException: Unknown animator name: translate at (...)
कोई विचार है कि मैं स्लाइडिंग प्रभाव कैसे बना सकता हूं और ऑब्जेक्ट का उपयोग उसी समय पर कर सकता हूं?
आपके समय के लिए धन्यवाद!
कोड मैं का उपयोग कर:
card_flip_right_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Before rotating, immediately set the alpha to 0. -->
<objectAnimator
android:duration="0"
android:propertyName="alpha"
android:valueFrom="1.0"
android:valueTo="0.0" />
<!-- Rotate. -->
<objectAnimator
android:duration="@integer/card_flip_time_full"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="rotationY"
android:valueFrom="180"
android:valueTo="0" />
<!-- Half-way through the rotation (see startOffset), set the alpha to 1. -->
<objectAnimator
android:duration="1"
android:propertyName="alpha"
android:startOffset="@integer/card_flip_time_half"
android:valueFrom="0.0"
android:valueTo="1.0" />
</set>
टुकड़ा एक और टुकड़ा बुला:
private void launchArticle(int prev, int pos){
ArticleFragment newFragment = new ArticleFragment();
Bundle args = new Bundle();
args.putString("pos", pos);
args.putInt("prev", prev);
newFragment.setArguments(args);
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fragment currFrag = (Fragment)getFragmentManager().findFragmentById(R.id.headlines_fragment);
if (currFrag != null) {
transaction.hide(currFrag);
}
transaction.setCustomAnimations(
R.animator.card_flip_right_in,
R.animator.card_flip_right_out,
R.animator.card_flip_left_in,
R.animator.card_flip_left_out
);
transaction.replace(R.id.fragment_container, newFragment, pos);
transaction.addToBackStack(null);
transaction.commit();
}
(घन रोटेशन यह 2 के बीच दिखना चाहिए)
अद्यतन:
मैं एक वर्ग है कि टुकड़े की मेरी framelayout मैं उपयोग कर रहा हूँ
SlidingFrameLayout.java
public class SlidingFrameLayout extends FrameLayout
{
private static final String TAG = SlidingFrameLayout.class.getName();
public SlidingFrameLayout(Context context) {
super(context);
}
public SlidingFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public float getXFraction()
{
final int width = getWidth();
if(width != 0) return getX()/getWidth();
else return getX();
}
public void setXFraction(float xFraction) {
final int width = getWidth();
setX((width > 0) ? (xFraction * width) : -9999);
}
public float getYFraction()
{
final int height = getHeight();
if(height != 0) return getY()/getHeight(); else return getY();
}
public void setYFraction(float yFraction) {
final int height = getHeight();
setY((height > 0) ? (yFraction * height) : -9999);
}
}
फैली का उपयोग कर पिछले समस्या को हल करने और ObjectAnimator को यह जोड़कर का प्रबंधन किया है :
<!-- Move -->
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@integer/card_flip_time_full"
android:interpolator="@android:anim/linear_interpolator"
android:propertyName="xFraction"
android:valueFrom="-1"
android:valueTo="0" />
यह बेहतर काम कर रहा है, लेकिन rottation कुल्हाड़ियों FrameLayout के बीच में हैं और यह माकी नहीं है एक घन के भ्रम ... क्या एक निश्चित बिंदु पर रोटेशन अक्ष सेट करना संभव है?
मेरे मामले में मुझे फ्रेमलेआउट के बजाय टुकड़ों के मूल दृश्य पर अतिरिक्त विधियां (getXFraction, setXFraction ...) थी, लेकिन परिणाम वही है .. धन्यवाद – codeskraps
@codeskraps क्या आप दिखा सकते हैं कि आपने कैसे किया टुकड़ों के मूल दृश्य पर अतिरिक्त विधियों को जोड़ा? मैं एक टुकड़ा स्लाइड करना चाहता हूं और ऐसा करने के लिए मैं विस्तारित फ्रेमलाउट का उपयोग कर रहा हूं। यह काम करता है लेकिन इसमें कुछ मुद्दे हैं। मैं ऐसा करने के लिए एक बेहतर तरीका तलाश रहा हूं। – crubio