ListView 의 Layout Animation, listSelector 미끄럼 효과 와 일부 속성

4903 단어
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  

list_item 1. xml 애니메이션 효과 파일 입 니 다. 투명 성 만 바 뀌 었 습 니 다. listview 가 Activity 에 들 어 갈 때 위 에서 아래로 하나씩 표 시 됩 니 다.
<?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>

자바 코드 설정 을 보 겠 습 니 다:
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); 

좋은 웹페이지 즐겨찾기