滑动卡片式效果

6 篇文章 0 订阅
1 篇文章 0 订阅

滑动卡片式效果

效果图

代码实现

静态布局

使用瀑布流效果的StaggeredGridView控件作为GroupView.


    <com.etsy.android.grid.StaggeredGridView
    android:id="@+id/page"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:column_count="1"
    app:item_margin="8dp"
    >

    </com.etsy.android.grid.StaggeredGridView>

定义item布局


    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="@drawable/card_bg"
              android:descendantFocusability="blocksDescendants"
              android:orientation="vertical"
              android:padding="8dp"
    >

    <TextView
        android:id="@+id/tv_caption"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="caption"
        android:textSize="20sp"
        android:textStyle="normal"
        />

    <ImageView
        android:id="@+id/iv_normal"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="#c9c9c9"
        android:minHeight="200dp"
        android:scaleType="centerCrop"
        />

    </LinearLayout>

动画实现

这里需要使用listviewanimationsnineoldandroids两个有关动画效果的库,继承AnimationAdapter自定义CardsAnimationAdapter,覆写public Animator[] getAnimators(ViewGroup viewGroup, View view)方法,为每个view指定动画效果。


    public class CardsAnimationAdapter extends AnimationAdapter {


    private float mTranslationY = 400;
    private float mRotationX = 15;
    private long mDuration = 400;
    private long mDelay = 30;

    public CardsAnimationAdapter(BaseAdapter baseAdapter) {
        super(baseAdapter);
    }

    @Override
    protected long getAnimationDelayMillis() {
        return mDelay;
    }

    @Override
    protected long getAnimationDurationMillis() {
        return mDuration;
    }

    @Override
    public Animator[] getAnimators(ViewGroup viewGroup, View view) {
        return new Animator[]{
                ObjectAnimator.ofFloat(view, "translationY", mTranslationY, 0),
                ObjectAnimator.ofFloat(view, "rotationX", mRotationX, 0)
        };
    }

    }

将原生的adapter装饰成带有动画效果的CardsAnimationAdapter.


        private StaggeredGridView mPage;
        mPage = (StaggeredGridView) findViewById(R.id.page);

        mAdapter=new PageAdapter(this, imgIds);
        AnimationAdapter animationAdapter = new CardsAnimationAdapter(mAdapter);
        animationAdapter.setAbsListView(mPage);

        mPage.setAdapter(animationAdapter);

完整代码

github

参考

9GAG-Android (unofficial)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值