使用资源文件配置布局动画

使用AndroidStudio配置动画布局,首先要创建animation的文件夹,右键New一个Android Resource Directory,然后在这个文件夹里面再右键New一个Animation Resource File,就可以创建动画的xml了:
这里创建一个scale_0_1.xml:
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0"
android:toXScale="1"
android:fromYScale="0"
android:toYScale="1"
android:duration = "1000">
</scale>
再创建一个listview_anim.xml来封装这个动画:
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/scale_0_1"
android:delay="0.5"
>
</layoutAnimation>
然后在main.xml里面就可以使用了:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@android:id/list"
    android:layoutAnimation="@anim/listview_anim"></ListView>

</LinearLayout>
注意在MainActivity是继承自ListActivity的:
public class MainActivity extends ListActivity {}
并且里面设置的是main.xml:
setContentView(R.layout.main);
所以在main.xml里面就必须有一个ListView,并且它的id一定要是"android:id/list",其他的不行,"@+id:list都不行"。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容