New Google Now and Google+ card interface

前端 未结 6 1383
感动是毒
感动是毒 2020-12-12 08:27

Google Now and Google+ (Android) both make use of a card-like interface.

\"enter

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 09:24

    I have posted a tutorial on how to replicate / create Google Cards style layout here.

    Key steps

    1. Create a custom layout
    2. Add observer for drawing children
    3. Animate alternating cards

    Heres a code snippet

    @Override
    public void onGlobalLayout() {
        getViewTreeObserver().removeGlobalOnLayoutListener(this);
    
        final int heightPx = getContext().getResources().getDisplayMetrics().heightPixels;
    
        boolean inversed = false;
        final int childCount = getChildCount();
    
        for (int i = 0; i < childCount; i++) {
            View child = getChildAt(i);
    
            int[] location = new int[2];
    
            child.getLocationOnScreen(location);
    
            if (location[1] > heightPx) {
                break;
            }
    
            if (!inversed) {
                child.startAnimation(AnimationUtils.loadAnimation(getContext(),
                        R.anim.slide_up_left));
            } else {
                child.startAnimation(AnimationUtils.loadAnimation(getContext(),
                        R.anim.slide_up_right));
            }
    
            inversed = !inversed;
        }
    
    }
    

提交回复
热议问题