Hacksix adds pleasing animation effects to the viewgroup subview

Source: Internet
Author: User

1. By default, the subview added to viewgrop is displayed directly. There is a relatively simple way to add an animation effect for this process.

2. knowledge Point: The layoutanimationcontroller class is used to add animation effects to the sub-view. The layoutanimationcontroller must emphasize that different animation effects cannot be specified for each sub-view, however, the animation effect time can be displayed for each subview. 3. Example: The following shows how to add an animation effect to the subview of listview by combining the Alpha animation and the translate animation ..
There are two ways to use layoutanimationcontriller: one is to use it directly in the code or configure it in the XML text room. The following example will be used in the Code:
 1 public class MainActivity extends Activity { 2     private ListView mListView; 3     @Override 4     protected void onCreate(Bundle savedInstanceState) { 5         super.onCreate(savedInstanceState); 6         setContentView(R.layout.activity_main); 7         mListView = (ListView) findViewById(R.id.listView); 8         mListView.setAdapter(new ArrayAdapter<String>(this, 9                 android.R.layout.simple_list_item_1, Countries.COUNTRIES));10         AnimationSet set = new AnimationSet(true);11         Animation alpha = new AlphaAnimation(0.0f, 1.0f);12         alpha.setDuration(2000);13         Animation translate = new TranslateAnimation(14                 Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,15                 0.0f, Animation.RELATIVE_TO_SELF, -1.0f,16                 Animation.RELATIVE_TO_SELF, 0.0f);17         translate.setDuration(1000);18         set.addAnimation(alpha);19         set.addAnimation(translate);20         LayoutAnimationController controller = new LayoutAnimationController(21                 set);22         mListView.setLayoutAnimation(controller);23     }24 }  
activity_main.xml
 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2     xmlns:tools="http://schemas.android.com/tools" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     android:orientation="vertical" 6     tools:context=".MainActivity" > 7  8     <ListView 9         android:id="@+id/listView"10         android:layout_width="match_parent"11         android:layout_height="match_parent" >12     </ListView>13 14 </LinearLayout>

 

 
  

Hacksix adds pleasing animation effects to the viewgroup subview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.