zoukankan      html  css  js  c++  java
  • Android中的布局动画

    简介

    布局动画是给布局的动画,会影响到布局中子对象

    使用方法

    给布局添加动画效果:

    先找到要设置的layout的id,然后创建布局动画,创建一个LayoutAnimationController,并把动画传给它,最后就可以设置这个布局的lac。

    sa的duration是整个布局动画完成的时间,LAC的delay是指每一个子对象间的延迟时间。

            LinearLayout layout = (LinearLayout) findViewById(R.id.activity_main);
            ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1);
            sa.setDuration(350);
            LayoutAnimationController lac = new LayoutAnimationController(sa, 0.5f);
            layout.setLayoutAnimation(lac);

    布局内容改变动画:

    通过设置layout的animateLayoutChange属性,可以达到布局内容改变的时候产生动画效果。

    给列表添加布局动画:

    与给布局添加动画效果类似,只需要创建lac,并设置给list即可。

    public class MainActivity extends ListActivity {
    private ArrayAdapter<String> adapter;
    private LayoutAnimationController lac;
    private ScaleAnimation sa;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[]{"Hello", "world", "!"});
    setListAdapter(adapter);
    sa = new ScaleAnimation(0, 1, 0, 1);
    sa.setDuration(1000);
    lac = new LayoutAnimationController(sa, 0.5f);
    getListView().setLayoutAnimation(lac);
    }
    }

    也可以通过xml给布局配置动画效果:

    首先创建scale.xml:

    <scale android:fromXScale="0"
           android:toXScale="1"
           android:toYScale="1"
           android:fromYScale="0"
           android:duration="3000"
           xmlns:android="http://schemas.android.com/apk/res/android">
    
    </scale>

    然后创建layoutAnimation:

    <layoutAnimation android:animation="@anim/scale"
                     android:delay="0.5"
                     xmlns:android="http://schemas.android.com/apk/res/android">
    
    </layoutAnimation>

    最后可以在布局的组件中指定layoutAnimation:

    <ListView
                android:id="@android:id/list"
                android:layoutAnimation="@anim/listview_anim"
                android:layout_width="match_parent"
                android:layout_height="match_parent"></ListView>
  • 相关阅读:
    sqlserver中自定义函数+存储过程实现批量删除
    javascript的词法分析
    struts2 OGNL(Object-Graph Navigation Language) 井号,星号,百分号
    SimpleAdapter
    IntentService源码分析
    Service 的 onStartCommand(Intent, int, int) 返回值
    AppFog使用
    Looper分析。ThreadLocal有关
    HandlerThread分析
    form表单的enctype属性
  • 原文地址:https://www.cnblogs.com/dracohan/p/6003400.html
Copyright © 2011-2022 走看看