2011-12-31 12 views
55

टेक्स्ट व्यू अदृश्य क्यों नहीं होता है? यहाँएक दृश्य के बाद दृश्यता कार्य क्यों सेट नहीं किया गया है एनिमेटेड है?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
    android:id="@+id/tvRotate" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Rotate Me" 
/> 
</LinearLayout> 

..और मेरे गतिविधि है:

यहाँ मेरी लेआउट एक्सएमएल है

public class RotateMeActivity extends Activity 
{ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     TextView tvRotate = (TextView) findViewById(R.id.tvRotate); 

     RotateAnimation r = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
     r.setDuration(0); 
     r.setFillAfter(true); 
     tvRotate.startAnimation(r); 
     tvRotate.setVisibility(View.INVISIBLE); 
    } 
} 

मेरा लक्ष्य एक दृश्य को घुमाने और फिर छिपाने के लिए और कोड में यह दिखाने के लिए सक्षम होने के लिए है सेट दृश्यता सेट करके। निम्नलिखित काम करता है, लेकिन setRotation केवल API स्तर में उपलब्ध है 11. मैं 10.

tvRotate.setRotation(180);//instead of the RotateAnimation, only works in API Level 11 
tvRotate.setVisibility(View.INVISIBLE); 

उत्तर

18

सभी एनिमेशन (इससे पहले कि एंड्रॉयड 3.0) वास्तव में एक बिटमैप जो एक है पर लागू होते हैं एपीआई स्तर में यह करने के लिए कोई तरीका होना चाहिए अपने मूल दृश्य के बजाय अपने दृश्य का स्नैपशॉट। जब आप सत्य के बाद भरना सेट कर रहे हैं तो वास्तव में इसका मतलब है कि बिटमैप आपके दृश्य के बजाय स्क्रीन पर प्रदर्शित होना जारी रहेगा। यही कारण है कि setVisibility का उपयोग करने पर दृश्यता नहीं बदलेगी और यही कारण है कि आपका दृश्य अपनी नई (घुमावदार) सीमाओं में स्पर्श ईवेंट नहीं प्राप्त करेगा। (लेकिन चूंकि आप 180 डिग्री पर घूम रहे हैं जो कोई मुद्दा नहीं है)।

+1

तो, बी को छिपाने का कोई तरीका है घुमावदार के बाद बनी रहती है? – ZippyFerguson

+0

एक ही समस्या ... – SunnySonic

1

मुझे एपीआई स्तर 11 की आवश्यकता होती है और इसे पूरा करने के लिए सेटरोटेशन का उपयोग करना समाप्त हो जाता है। यह एक बहुत ही सरल आवश्यकता की तरह लगता है जिसे पूर्व-हनीकॉम्ब नहीं किया जा सकता है। मैं बस इतना करना चाहता था कि एक बटन घुमाए और फिर इसे छुपाएं/दिखाएं।

1

मैं इसके लिए एक समाधान के साथ आया: मूल रूप से सेट करने से पहले आप सही दृश्य (View.GONE) कॉल करें, अवधि = 0 सेटफिलएफ़टर (झूठी) के साथ एक एनीमेशन करें और कोण को रोटेशन के वर्तमान कोण से सेट/से सेट करें ।

यह सेटफिलएटर बिटमैप को साफ़ करेगा और दृश्य को जाने की अनुमति देगा।

7

इसके आसपास काम करने का एक और तरीका है अपने एनिमेटेड व्यू को दूसरे दृश्य में लपेटना और उस रैपर व्यू की दृश्यता सेट करना।

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
    <FrameLayout 
     android:id="@+id/animationHoldingFrame" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:id="@+id/tvRotate" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Rotate Me" 
     /> 
    </FrameLayout> 
</LinearLayout> 

और कोड तो यह हो जाता है:

TextView tvRotate = (TextView) findViewById(R.id.tvRotate); 
FrameLayout animationContainer = (FrameLayout)findViewById(R.id.animationHoldingFrame) 

RotateAnimation r = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
r.setDuration(0); 
r.setFillAfter(true); 
tvRotate.startAnimation(r); 
animationContainer.setVisibility(View.INVISIBLE); 
+0

बिल्कुल वही जो मैं खोज रहा था :-) – Couitchy

151

मुझे देखें की clearAnimation बुला लिए समस्या तय। मेरे मामले में मैं fillAfter सेट पर सत्य के साथ अनुवाद करने के बाद व्यू को अपनी मूल स्थिति में सेट करना चाहता था।

+6

मुझे यह समस्या हो रही थी और यह पुष्टि कर सकता है कि स्पष्टता चाल है। –

+0

कृपया कोई इस जवाब को स्वीकार कर लेता है क्योंकि वह वह है जो आपके ** ** को संघर्ष के दिन के बाद बचाता है;) thx! –

+4

मैं पुष्टि करता हूं कि यह समस्या को हल करता है।'एनीमेशन लिस्टनर' में 'ऑनएनीमेशन एंड()' में अधिक सहायक होने के लिए इसका उपयोग करें;) – czaku

5

एनीमेशन के बाद setVisibility से पहले इस प्रयोग पूरा हो गया है:

anim.reverse(); 
anim.removeAllListeners(); 
anim.end(); 
anim.cancel(); 

जहां anim अपने ObjectAnimator

है, लेकिन यदि आप एनीमेशन वर्ग का उपयोग कर रहे है, तो बस कार्य करें: पर

view.clearAnimation(); 

जिस दृश्य पर एनीमेशन किया गया था

संबंधित मुद्दे

 संबंधित मुद्दे