卡片横向层叠android,Android实现3D层叠式卡片图片展示

本文实例为大家分享了Android实现3D层叠式卡片图片展示的具体代码,供大家参考,具体内容如下

先看效果

83e8feb04c1623292583846480586dd6.gif

好了效果看了,感兴趣的往下看哦!

整体实现思路

1、重写RelativeLayout 实现 锁定宽高比例的 RelativeLayout

2、自定义一个支持滑动的面板 继承 ViewGroup

3、卡片View绘制

4、页面中使用布局

首先为了更好的展示图片我们重写一下 RelativeLayout 编写一个锁定宽高比例的 RelativeLayout

AutoScaleRelativeLayout

public class AutoScaleRelativeLayout extends RelativeLayout {

//宽高比例

private float widthHeightRate = 0.35f;

public AutoScaleRelativeLayout(Context context) {

this(context, null);

}

public AutoScaleRelativeLayout(Context context, AttributeSet attrs) {

this(context, attrs, 0);

}

public AutoScaleRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

//通过布局获取宽高比例

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.card, 0, 0);

widthHeightRate = a.getFloat(R.styleable.card_widthHeightRate, widthHeightRate);

a.recycle();

}

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

// 调整高度

int width = getMeasuredWidth();

int height = (int) (width * widthHeightRate);

ViewGroup.LayoutParams lp = getLayoutParams();

lp.height = height;

setLayoutParams(lp);

}

}

这样我们就编写好了我们想要的父布局

使用方法

android:id="@+id/card_top_layout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

card:widthHeightRate="0.6588">

android:id="@+id/card_image_view"

android:layout_width="fill_parent"

android:layout_height="match_parent"

android:scaleType="fitXY" />

android:id="@+id/maskView"

android:layout_width="fill_parent"

android:layout_height="match_parent"

android:background="?android:attr/selectableItemBackground"</

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值