MianAcitivty.java: public class MainActivity extends AppCompatActivity { private ListView list; private String[] str_name = new String[]{"item1","item2","item3" ,"item4" ,"item5" , "item6" , "item7", "item8", "item9", "item10"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); list = (ListView) findViewById(R.id.list); list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, str_name)); Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim_item); LayoutAnimationController controller = new LayoutAnimationController(animation); controller.setDelay(0.5f); controller.setOrder(LayoutAnimationController.ORDER_NORMAL); list.setLayoutAnimation(controller); } } XML:<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.hxh.listitemanimation.MainActivity"> <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" tools:layout_editor_absoluteY="0dp" tools:layout_editor_absoluteX="8dp"></ListView> </LinearLayout> anim_item:<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:shareInterpolator="true" > <alpha android:fromAlpha="0.0" android:toAlpha="1.0"/> <translate android:fromXDelta="500" android:fromYDelta="0"/> </set>
ListView增加Item动画例子
最新推荐文章于 2021-08-30 21:02:58 发布