| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx

Android特效开发

0
Android Java C/C++ Go list 19232 次浏览
Android特效开发

本次我要向大家介绍一个Android特效,这个特效也是我在某款软件中看到的,至于软件叫什么,
好了,我来上一张动态效果图 在下面,屏幕小的请往下拉。

我不知道原软件是怎么个实现法,在这里我只是说说我的实现方法,代码可能不太好,这只是本人的一个idea 原理很简单!


改变按钮的宽度,每次当你点击按钮时,只有两个按钮改变宽度,一个变长,一个变短,只是这个变化是慢慢

进行,不是秒变的,你懂的,这就是动画效果。你点击短的按钮后会渐渐地变长,长的按钮会随着被压缩,其他按钮宽度不变。

 我写这篇文章想起到一个抛砖引玉的效果,希望读者看了这篇文章后继续写个更好的文章。当然你不要忘记我啊,

记得要与我和大家分享啊。

 下面是特效Demo运行后的效果图:


可以看到view被挤压的效果,点击短的view会慢慢长大。在短的view慢慢长大的同时,最长的view会慢慢缩小,而且每次动画结束后都

有一个最长的view 。我这里所说的view在本次Demo中是按钮,当然你也可以换成其他的控件,或者是ViewGroup的子类也行。
[java] view plaincopyprint?

    public class PinchActivity extends Activity implements View.OnClickListener {  
      
        private final static String TAG = "MainActivity";  
          
        // 屏幕宽度  
        private int screentWidth = 0;  
          
        // View可伸展最长的宽度  
        private int maxWidth;  
          
        // View可伸展最小宽度  
        private int minWidth;  
          
        // 当前点击的View  
        private View currentView;  
          
        // 显示最长的那个View  
        private View preView;  
          
        // 主布局ViewGroup  
        private LinearLayout mainContain;  
          
        // 标识符 动画是否结束  
        private boolean animationIsEnd = true;  
          
        // 变大操作  
        private static final int OPE_BIG = 1;  
          
        // 变小操作  
        private static final int OPE_SMALL = 2;  
          
        // 当前操作 -1表示无效操作  
        private int currentOpe = -1;  
          
        // 前进的步伐距离  
        private static final int STEP = 10;  
      
        @Override  
        protected void onCreate(Bundle savedInstanceState)   
        {  
      
            super.onCreate(savedInstanceState);  
              
            setContentView(R.layout.activity_main);  
      
            initCommonData();  
              
            initViewData();  
              
            measureWidth(screentWidth);   
      
        }  
      
        private void initViewData() {  
      
            mainContain = (LinearLayout) this.findViewById(R.id.main_contain);  
            View child;  
            int childCount = mainContain.getChildCount();  
            for (int i = 0; i < childCount; i++) {  
                child = mainContain.getChildAt(i);  
                child.setOnClickListener(this);  
            }  
        }  
          
        private void initCommonData()  
        {  
            DisplayMetrics metric = new DisplayMetrics();  
            getWindowManager().getDefaultDisplay().getMetrics(metric);  
            screentWidth = metric.widthPixels; // 屏幕宽度(像素)  
        }  
      
      
        private void setCurrentViewParams() {  
      
            if (currentView == null) {  
                return;  
            }  
            LayoutParams params = currentView.getLayoutParams();  
            if (params == null) {  
                return;  
            }  
            int realWidth = params.width;  
            int nextWidth = 0;  
            if (currentOpe == OPE_BIG) {  
                nextWidth = realWidth + STEP;  
            } else if (currentOpe == OPE_SMALL) {  
                nextWidth = realWidth - STEP;  
            }  
            if (nextWidth > maxWidth) {  
                nextWidth = maxWidth;  
            } else if (nextWidth < minWidth) {  
                nextWidth = minWidth;  
            }  
            params.width = nextWidth;  
            currentView.setLayoutParams(params);  
            if (nextWidth == maxWidth || nextWidth == minWidth) {  
                animationIsEnd = true;  
                onOffClickable();  
                stopAnimation();  
                return;  
            }  
            mHandler.sendEmptyMessageDelayed(1, 20);  
        }  
      
        // 初始化宽度 测量max min 长度  
        private void measureWidth(int screenWidth) {  
              
            int halfWidth = screenWidth / 2;  
            maxWidth = halfWidth - 50;  
            minWidth = (screenWidth - maxWidth) / (mainContain.getChildCount() - 1);  
      
            View child;  
            int childCount = mainContain.getChildCount();  
            for (int i = 0; i < childCount; i++) {  
                child = mainContain.getChildAt(i);  
                LayoutParams params = child.getLayoutParams();  
                if (i == 0) {  
                    preView = child;  
                    params.width = maxWidth;  
                } else {  
                    params.width = minWidth;  
                }  
      
                child.setLayoutParams(params);  
            }  
        }  
      
        // 这里用handler更新界面  
        private Handler mHandler = new Handler() {  
      
            @Override  
            public void handleMessage(Message msg) {  
      
                if (msg.what == 1) {  
                    setCurrentViewParams();  
                }   
            }  
      
        };  
      
        // 停止动画  
        private void stopAnimation() {  
            currentOpe = -1;  
            currentView = null;  
        }  
      
        private void startAnimation() {  
      
            if (currentView == null || currentOpe == -1) {  
                Log.d(TAG, "无效动画");  
                return;  
            }  
              
            animationIsEnd = false;  
            onOffClickable();  
            mHandler.sendEmptyMessage(1);  
        }  
      
        @Override  
        public void onClick(View v) {  
              
            int id = v.getId();  
              
            switch (id) {  
              
            case R.id.btnOne:  
                currentView = mainContain.getChildAt(0);  
                break;  
            case R.id.btnTwo:  
                currentView = mainContain.getChildAt(1);  
                break;  
            case R.id.btnThree:  
                currentView = mainContain.getChildAt(2);  
                break;  
            case R.id.btnFour:  
                currentView = mainContain.getChildAt(3);  
                break;  
            }  
      
            Log.i(TAG, ((Button) currentView).getText().toString() + " click");  
              
            if (currentView != null && animationIsEnd) {  
                  
                int currentViewWidth = currentView.getWidth();  
                  
                if (currentViewWidth == maxWidth) {  
                    currentOpe = OPE_SMALL;  
                } else {  
                    currentOpe = OPE_BIG;  
                }  
                  
                clickEvent(currentView);  
                  
                startAnimation();  
            }  
      
        }  
      
        private void clickEvent(View view) {  
            View child;  
            int childCount = mainContain.getChildCount();  
            for (int i = 0; i < childCount; i++) {  
                child = mainContain.getChildAt(i);  
                if (preView == child) {  
                    LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) child  
                            .getLayoutParams();  
                    params.weight = 1.0f;  
                    child.setLayoutParams(params);  
                } else {  
                    LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) child  
                            .getLayoutParams();  
                    params.weight = 0.0f;  
                    params.width = minWidth;  
                    child.setLayoutParams(params);  
                }  
            }  
            preView = view;  
            printWeight();  
        }  
      
        private void printWeight() {  
            View child;  
            int childCount = mainContain.getChildCount();  
            for (int i = 0; i < childCount; i++) {  
                child = mainContain.getChildAt(i);  
                LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) child  
                        .getLayoutParams();  
                Log.i("mm1", ((Button) child).getText() + ": " + params.weight);  
            }  
        }  
          
        //   
        private void onOffClickable()  
        {  
            View child;  
            boolean clickable = animationIsEnd;  
            int childCount = mainContain.getChildCount();  
            for (int i = 0; i < childCount; i++) {  
                child = mainContain.getChildAt(i);  
                child.setClickable(clickable);  
            }  
        }  
      
    }
大家学了过后,有没有帮助啊。学android特效上IT蓝豹。

47个答案

0

ฝาก30รับ100Latest 2021 Promotion Hits Slots Can play all game camps, new members, deposit 30, get 100, give away free credit, no need to deposit, no need to share Promotion deposit 30 get 100 unlimited withdrawal No minimum deposit

0

พีจีสล็อตA very popular game camp that played many years ago. Until now because it's a simple game. The rules are not complicated, the game is played for fun.

0

slot We have included all web slots camps. already here The best new online slots website of the year 2021, the only website to play slots for all game camps. From leading camps across the country, including pg slot, joker game, slotxo, live22 and many others

0

สล็อต789Online slots no minimum deposit-withdrawal with automation As fast as 8 seconds, including online slots from leading slot game camps

0

ฝาก20รับ100New arrivals, latest 2021 with special conditions 20 get 100

0

slot currently has online slot games. Comes in a new format with 3D images as slots online, direct websites and leading game camps such as PG SLOT JOKER GAME, new member registration, 100% bonus and many more slots

0

เครดิตฟรีcurrently has online slot games. Comes in a new format with 3D images as slots online, direct websites and leading game camps such as PG SLOT JOKER GAME, new member registration, 100% bonus and many more slots

0

slot We have included all web slots camps. already here The best new online slots website of the year 2021, the only website to play slots for all game camps. From leading camps across the country, including pg slot, joker game, slotxo, live22 and many others

0

สล็อต789Online slots no minimum deposit-withdrawal with automation As fast as 8 seconds, including online slots from leading slot game camps

0

ฝาก20รับ100New arrivals, latest 2021 with special conditions 20 get 100

0

slot currently has online slot games. Comes in a new format with 3D images as slots online, direct websites and leading game camps such as PG SLOT JOKER GAME, new member registration, 100% bonus and many more slots

0

เครดิตฟรีcurrently has online slot games. Comes in a new format with 3D images as slots online, direct websites and leading game camps such as PG SLOT JOKER GAME, new member registration, 100% bonus and many more slots

0

PG SLOTThe latest with a game system designed for direct pg slot players because the game format is very advanced, can play pg slot auto via ios and android systems, supports playing pg slots via mobile Deposit-withdraw automatically in just 8 seconds

0

Your article is providing the best solutions for app development. We are from Local Moving Services in Fort Lauderhill FL, providing company whose aim is to provide you with trusted services. We have years of experience. Contact us to get a free consultation.

0

ดาวน์โหลดjoker123 auto Online slots, mobile phones, new online slots games, online slots that are the hottest in 2020, with low capital, can play.

0

ทางเข้า joker123 Top camp slots games Genuine license from PGSLOT game camp, online slots, direct web slot game service.

0

joker PG SLOT Game is a new and hot slot game that is gaining popularity right now, online slots, direct websites, not through agents.

0

เว็บตรง สล็อต PG SLOT online slots games A game that is popular with players all over the world right now. Your slots play will never be boring again.

0

Slots Free Trial Playable Withdrawable Free Trial Playable Withdraw Real Money Free credit to play slots Terms and conditions are as specified by the website. ทดลองเล่นสล็อต

0

The number 1 online slot game in Thailand, slot 888 online that includes the 888 slot game camp to play more than 300 games. สล็อต 888

1 2 3