android – Recycler视图点击动画

android – Recycler视图点击动画,第1张

概述我正在尝试将一些点击动画 as shown here添加到我的回收站视图,但未成功.这是我的一些代码. 在我的活动中 @Overrideprotected void onCreate(Bundle savedInstanceState) { ... mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view); 我正在尝试将一些点击动画 as shown here添加到我的回收站视图,但未成功.这是我的一些代码.

在我的活动中

@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    ...    mRecyclerVIEw = (RecyclerVIEw) findVIEwByID(R.ID.recycler_vIEw);    ItemOffsetdecoration itemdecoration = new ItemOffsetdecoration(this,R.dimen.card_item_offset);    mRecyclerVIEw.addItemdecoration(itemdecoration);    mLayoutManager = new linearlayoutmanager(this);    mRecyclerVIEw.setLayoutManager(mLayoutManager);    mAdapter = new CustomAdapter(this);    mRecyclerVIEw.setAdapter(mAdapter);}

在我的VIEwHolder中

public CustomVIEwHolder(VIEw itemVIEw) {    super(itemVIEw);    this.itemVIEw.setonClickListener(new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            /* on click stuff here */        }    });}

在我的CardVIEw.xml里面

<?xml version="1.0" enCoding="utf-8"?><androID.support.v7.Widget.CardVIEw    xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:card_vIEw="http://schemas.androID.com/apk/res-auto"    androID:ID="@+ID/card_loading"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    card_vIEw:cardCornerRadius="4dp"    androID:clickable="true"    androID:background="?androID:attr/selectableItemBackground">    <TextVIEw        androID:ID="@+ID/card_message"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content" /></androID.support.v7.Widget.CardVIEw>

不知道问题出在哪里,但提前谢谢你的帮助=)

解决方法 这被称为涟漪效应,你正在尝试用背景代替前景
androID:focusable="true"androID:clickable="true"androID:foreground="?androID:attr/selectableItemBackground"

你也可以自定义

<ripple xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:color="@color/colorcode">    <item        androID:ID="@androID:ID/mask"        androID:drawable="@color/colorcode" /></ripple>

为了支持旧版本,你可以这样做

<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID">    <item androID:state_pressed="true">        <shape androID:shape="rectangle">            <solID androID:color="@color/colorcode" />        </shape>    </item>    <item>        <shape androID:shape="rectangle">            <solID androID:color="@androID:color/colorcode" />        </shape>    </item></selector>
总结

以上是内存溢出为你收集整理的android – Recycler视图点击动画全部内容,希望文章能够帮你解决android – Recycler视图点击动画所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1137588.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存