• Android自定义有动画效果,用于选择的Layout


    public class SelectLayout extends LinearLayout {
    
        private AnimationSet mInAnime;
        private AnimationSet mOutAnime;
        private Animation mAlphaAnime;
        private View mCheckView;
        private View[] mViewArray;
        public SelectLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
            // TODO 鑷姩鐢熸垚鐨勬瀯閫犲嚱鏁板瓨鏍?
        }
        
        public void iniSelectLayout(){
            
        
            iniAnimation();
            mViewArray=new View[getChildCount()];
            for(int i=0;i<getChildCount();i++){
                mViewArray[i]=getChildAt(i);
                if(i>0)
                    mViewArray[i].startAnimation(mAlphaAnime);
            }
            
            mCheckView=mViewArray[0];
            mCheckView.startAnimation(mInAnime);
            
            MyOnClickListener tmp=new MyOnClickListener();
            for(View item:mViewArray)
                item.setOnClickListener(tmp);
            
            
            
        }
        
        
        private void iniAnimation(){
            mInAnime=new AnimationSet(false);
            ScaleAnimation tmp=new ScaleAnimation(1, 1.2f, 1, 1.2f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            tmp.setDuration(300);
            AlphaAnimation tmp2=new AlphaAnimation(0.7f, 1);
            tmp2.setDuration(300);
            mInAnime.addAnimation(tmp);
            mInAnime.addAnimation(tmp2);
            mInAnime.setFillAfter(true);
            
            tmp=new ScaleAnimation(1.2f, 1, 1.2f, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            tmp.setDuration(300);
            tmp2=new AlphaAnimation(1, 0.7f);
            tmp2.setDuration(300);
            mOutAnime=new AnimationSet(false);
            mOutAnime.addAnimation(tmp);
            mOutAnime.addAnimation(tmp2);
            mOutAnime.setFillAfter(true);
            
            mAlphaAnime=new AlphaAnimation(0.7f,0.7f);
            mAlphaAnime.setFillAfter(true);
        }
        
        public View getSelectView(){
            return mCheckView;
        }
        
        private class MyOnClickListener implements OnClickListener{
    
            @Override
            public void onClick(View v) {
                // TODO 鑷姩鐢熸垚鐨勬柟娉曞瓨鏍?
                if(!v.equals(mCheckView)){
                    
                for(int i=0;i<mViewArray.length;i++){
                    if(!mViewArray[i].equals(v)&&!mViewArray[i].equals(mCheckView))
                        mViewArray[i].startAnimation(mAlphaAnime);
                }
                v.startAnimation(mInAnime);
                mCheckView.startAnimation(mOutAnime);
                
            
                mCheckView=v;
                
                
                }
            }
            
        }

    继承自LinearLayout,在xml里当LinearLayout用就行了,调用iniSelectLayout后会有类似RadioGroup的功能,被选中的子View会放大,没被选中的是半透明。注意如果子View的背景是jpg的话会出现闪烁,png不会。

  • 相关阅读:
    Java判断字符串是否包含数字
    char 与 String 之间的转换
    hive与hbase整合方式和优劣
    曾经的你-许巍
    Hbase表重命名 表改名
    Eclipse 快键键(持续更新)
    Linux 查看一个端口的连接数
    hbase性能调优(转载)
    Hbase优化记录
    记录下Linux难记实用的命令
  • 原文地址:https://www.cnblogs.com/kagami/p/3046675.html
Copyright © 2020-2023  润新知