本文共 2110 字,大约阅读时间需要 7 分钟。
LayoutAnimationController动画效果,一次出现
一、布局文件使用public class MainActivity extends AppCompatActivity { private ListView mListView; private static final String[] STRINGS = { "BruceZhang", "Alpha", "Translate", "Blanklin", "Rotate", "GreenFrank" }; private ArrayAdaptermAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mListView = (ListView) this.findViewById(R.id.listView); mAdapter = new ArrayAdapter<>(this, R.layout.item_list, STRINGS); } public void test(View view) { mListView.setAdapter(mAdapter); } public void clear(View view) { mListView.setAdapter(null); }}
二、代码配置
public class MainActivity extends AppCompatActivity { private ListView mListView; private static final String[] STRINGS = { "BruceZhang", "Alpha", "Translate", "Blanklin", "Rotate", "GreenFrank" }; private ArrayAdaptermAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mListView = (ListView) this.findViewById(R.id.listView); mAdapter = new ArrayAdapter<>(this, R.layout.item_list, STRINGS); // 1. 创建一个Animation对象 Animation animation = AnimationUtils.loadAnimation(this, R.anim.list_item_alpha); // 2. 使用如下代码创建LayoutAnimationController对象 LayoutAnimationController lac = new LayoutAnimationController(animation); // 3. 设置控件显示的顺序 lac.setOrder(LayoutAnimationController.ORDER_RANDOM); // 4. 为ListView设置LayoutAnimationController尚需经 mListView.setLayoutAnimation(lac); } public void test(View view) { mListView.setAdapter(mAdapter); } public void clear(View view) { mListView.setAdapter(null); }}
转载地址:http://lxhsa.baihongyu.com/