2013-09-03 6 views
14

का उपयोग कर एंड्रॉइड ग्रोनरलाइटआउट बढ़ाना मैं स्क्रीन पर लेआउट दिखाने के लिए एनीमेशन का उपयोग करने की कोशिश कर रहा हूं। विचार यह है कि लेआउट 0 की ऊंचाई से शुरू होगा और 100% तक बढ़ जाएगा।एनीमेशन

मुझे इसके साथ वास्तविक समस्याएं हैं और कुछ सहायता की आवश्यकता है। किसी कारण से कोई एनीमेशन नहीं किया जाता है।

यहाँ मेरी एनीमेशन एक्सएमएल फ़ाइल है

<?xml version="1.0" encoding="utf-8"?> 

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <scale 
     android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
     android:fromXScale="0.0" 
     android:toXScale="1" 
     android:fromYScale="1.0" 
     android:toYScale="1.0" 
     android:fillAfter="false" 
     /> 

</set> 

लेआउट फ़ाइल बहुत ही बुनियादी है और साथ ही बहुत ही बुनियादी है और

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> 

<LinearLayout 
     android:id="@+id/dialog" 
     android:layout_width="wrap_content" 
     android:layout_height="200dp" 
     android:layout_centerHorizontal="true" 
     android:orientation="vertical" 
     android:layout_centerVertical="true" 
     android:background="@drawable/border"> 
    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="Phone" 
      android:id="@+id/textView"/> 
    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="Address" 
      android:id="@+id/textView1"/> 
    <Button android:id="@+id/btn1" 
      android:layout_width="200dp" 
      android:layout_height="wrap_content" 
      android:text="Action 1" 
      /> 
    <Button android:id="@+id/btn2" 
      android:layout_width="200dp" 
      android:layout_height="wrap_content" 
      android:text="Action 2" 
      /> 
</LinearLayout> 
<Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Animate" 
     android:id="@+id/btnAnimate" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" 
     android:onClick="animate"/> 
</RelativeLayout> 

मेरे गतिविधि कोड निम्नलिखित के रूप में बनाया गया है

public class MyActivity extends Activity implements Animation.AnimationListener{ 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
} 

public void animate(View view){ 
    LinearLayout dialog = (LinearLayout)findViewById(R.id.dialog); 
    dialog.setVisibility(LinearLayout.VISIBLE); 
    Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim); 
    Log.i("animate","Begin Animation"); 
    animation.reset(); 
    // animation.setFillAfter(true); 
    animation.setAnimationListener(this); 
    dialog.setAnimation(null); 
    Log.i("animate","End Animation"); 
} 

@Override 
public void onAnimationStart(Animation animation) { 
    //To change body of implemented methods use File | Settings | File Templates. 
} 

@Override 
public void onAnimationEnd(Animation animation) { 
    //To change body of implemented methods use File | Settings | File Templates. 
} 

@Override 
public void onAnimationRepeat(Animation animation) { 
    //To change body of implemented methods use File | Settings | File Templates. 
} 
} 

धन्यवाद

+0

समस्या क्या है:

तो इस तरह से anim फ़ोल्डर (grow_anim1)

गतिविधि वर्ग उपयोग में

में animation.xml जोड़ सकता हूँ? आपका कोड अब क्या कर रहा है? – nedaRM

+0

मेरा कोड बिल्कुल कुछ नहीं करता है। निष्पादन ठीक है लेकिन कोई एनीमेशन नहीं ... – svager

उत्तर

23

ठीक है, मैंने इसे समझ लिया।

एनीमेशन एक्सएमएल लेआउट

<?xml version="1.0" encoding="utf-8"?> 

<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:fillEnabled="true" 
android:fillAfter="true"> 
<scale 

     android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
     android:fromXScale="1.0" 
     android:toXScale="1.0" 
     android:fromYScale="0.0" 
     android:toYScale="1.0" 
     android:fillAfter="false" 
     /> 

</set> 

लेआउट एक्सएमएल फ़ाइल

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> 

    <LinearLayout 
     android:id="@+id/dialog" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:orientation="vertical" 
     android:layout_centerVertical="true" 
     android:visibility="invisible" 
     android:background="@drawable/border"> 
    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="Phone" 
      android:id="@+id/textView"/> 
    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="Address" 
      android:id="@+id/textView1"/> 
    <Button android:id="@+id/btn1" 
      android:layout_width="200dp" 
      android:layout_height="wrap_content" 
      android:text="Action 1" 
      /> 
    <Button android:id="@+id/btn2" 
      android:layout_width="200dp" 
      android:layout_height="wrap_content" 
      android:text="Action 2" 
      /> 
    </LinearLayout> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Animate" 
     android:id="@+id/btnAnimate" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" 
     android:onClick="animate"/> 
</RelativeLayout> 

और मेरी गतिविधि वर्ग

public class MyActivity extends Activity{ 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
} 

public void animate(View view){ 
    LinearLayout dialog = (LinearLayout)findViewById(R.id.dialog); 
    dialog.setVisibility(LinearLayout.VISIBLE); 
    Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim); 
    animation.setDuration(500); 
    dialog.setAnimation(animation); 
    dialog.animate(); 
    animation.start(); 
} 

} 
+0

मतलब विधि dialog.animate() क्या करता है,? – anivaler

+0

अब कहा जाता है कैसे android.R.anim * – delive

+0

के लिए। बाहर एनीमेशन क्या परिवर्तन anim फ़ाइल में आवश्यक ?? –

1

एनीमेशन कभी शुरू नहीं हुआ है। जोड़ने का प्रयास करें: animation.start()?

+0

ठीक है, मैं यह पता लगा, लेकिन मैं पूरा जवाब यहाँ पोस्ट नहीं कर सकते क्योंकि मेरी प्रतिष्ठा भी कम :( – svager

5

एंड्रॉयड 3.0 के लिए सबसे आसान तरीका है और इसके बाद के संस्करण के लिए इस गुण सेट करने के लिए है देखें कि आप बच्चे जोड़ना चाहते हैं:

आप, कस्टम लेआउट एनिमेशन की आपूर्ति एक LayoutTransition वस्तु बना सकते हैं और विधि setLayoutTransition() के साथ लेआउट के लिए यह आपूर्ति करने के लिए चाहते हैं

:

android:animateLayoutChanges="true"

आप अपना स्वयं का एनिमेशन बना सकते हैं।

अधिक जानकारी के लिए देखें: http://developer.android.com/training/animation/layout.html#activity

+0

यह एक गैर-जवाब है। ओपी एक कस्टम एनिमेशन के लिए पूछ रहा है, लेकिन आप की व्याख्या नहीं करते कैसे सब पर एक कस्टम एनिमेशन आपूर्ति करने के लिए। –

+0

ल्यूक के साथ सहमत हैं, आप उत्तर का सबसे महत्वपूर्ण हिस्सा चूक गए हैं। आपके उत्तर के आधार पर 'view.setLayoutTransition (नया लेआउटट्रांसशन))' समाधान है, लेकिन यह कुछ भी नहीं करता है। – TWiStErRob

2

एंड्रॉयड में एक बढ़ती LinearLayout डिजाइनिंग:

जो Xamarin की मोनो एंड्रॉयड उपयोग कर रहे हैं के लिए:

संसाधनों के तहत एक फ़ोल्डर anim बनाते हैं।

(मेरे मामले में मैं टुकड़ा उपयोग कर रहा हूँ)

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

using Android.App; 
using Android.Content; 
using Android.OS; 
using Android.Runtime; 
using Android.Util; 
using Android.Views; 
using Android.Widget; 
using Android.Views.Animations; 
namespace BehnoudAndroidApp { 
    public class StartPageFragment : Fragment{ 
     public override View OnCreateView(LayoutInflater p0, ViewGroup p1, Bundle p2){ 
      var rootView = p0.Inflate(Resource.Layout.StartPageLayout, p1, false); 

      LinearLayout menu1 = rootView.FindViewById<LinearLayout>(Resource.Id.linearlayout1); 

      Animation animation1 = AnimationUtils.LoadAnimation(this.Activity, Resource.Animation.grow_anim1); 

      animation1.Duration = 5000; 

      menu1.Click += delegate { menu1.StartAnimation(animation1); }; 

      return rootView; 
     } 
    } 
}