使用AndroidStudio配置動畫布局紊婉,首先要創(chuàng)建animation的文件夾憨愉,右鍵New一個Android Resource Directory,然后在這個文件夾里面再右鍵New一個Animation Resource File输钩,就可以創(chuàng)建動畫的xml了:
這里創(chuàng)建一個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>
再創(chuàng)建一個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都不行"联贩。