ListView的一些属性,xml设置:
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_vertical" android:layout_marginTop="90dip" > <RelativeLayout android:id="@+id/tt_list_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" > <ImageView android:layout_width="0dp" //这个ImageView就是listview的自定义listSelector android:layout_height="0dp" android:id="@+id/list_bg" android:background="@drawable/list_selector"/> <ListView android:id="@+id/tt_list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:divider="@android:color/transparent" android:scrollbars="none" android:layoutAnimation="@anim/animation" //listview进入Activity的动画效果xml设置方式 android:cacheColorHint="@color/transparent" //下面三行是去掉listView内容上滑和下滑出现的重叠黑线 android:fadingEdge="none" android:fadingEdgeLength="0dp" /> </RelativeLayout> </LinearLayout>animation.xml文件:
<?xml version="1.0" encoding="utf-8"?> <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="0.2" android:animationOrder="normal" android:animation="@anim/list_item1" /> //这里是放置了动画效果xml文件
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" android:shareInterpolator="true"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500"/> </set>
下面看java代码的设置:
listbgImage=(ImageView) findViewById(R.id.list_bg); tt_list.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, final View view,int position, long id) { itemPosition = position; //Runnable里面是设置选中项放大和字体设置成白色,没有选中的是灰色 handler.postDelayed(new Runnable() { @Overridepublic void run() { if(list_focuse!=null){ list_focuse.setTextColor(getResources().getColor(R.color.gray)); list_focuse.startAnimation(AnimationUtils.loadAnimation(WappushBindingActivity.this, R.anim.list_item_narrowed)); } final TextView t=(TextView) view.findViewById(R.id.name); t.startAnimation(AnimationUtils.loadAnimation(WappushBindingActivity.this, R.anim.list_item_blowup)); t.setTextColor(Color.WHITE); ist_focuse=t; }}, 200); //下面的if和else是设置自定义listSelector的滑动效果 if(firstFlag){ RelativeLayout.LayoutParams laypp=(RelativeLayout.LayoutParams) listbgImage.getLayoutParams(); laypp.width=view.getWidth();laypp.height=view.getHeight(); listbgImage.setLayoutParams(laypp); listbgImage.setX(view.getX()); listbgImage.setY(view.getY()); }else{ listbgImage.setX(0); listbgImage.setY(0); Animation ani=new TranslateAnimation(previousX, view.getX(), previousY, view.getY()); ani.setDuration(300); ani.setInterpolator(new AccelerateInterpolator()); ani.setFillAfter(true); listbgImage.startAnimation(ani); } firstFlag=false; previousX=view.getX(); previousY=view.getY(); } @Overridepublic void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); }代码动态设置listview进入activity的动画效果:
private LayoutAnimationController animationController; animationController = new LayoutAnimationController( AnimationUtils.loadAnimation(WappushBindingActivity.this, R.anim.list_item)); animationController.setOrder(LayoutAnimationController.ORDER_NORMAL); animationController.setDelay((float) 0.2); adapter = new ListAdapter(notseenlist); tt_list.setAdapter(adapter); //listview设置setAdapter的时候启动动画效果 tt_list.setLayoutAnimation(animationController);