gpt4 book ai didi

android - 放大 RecyclerView 中的项目以重叠 2 个相邻的项目 Android

转载 作者:可可西里 更新时间:2023-11-01 19:07:15 26 4
gpt4 key购买 nike

我将 RecyclerView 与 GridLayoutManager 结合使用。我想要实现的目标是当我点击一个项目时,它会放大并与相邻的项目重叠。就像下图(在Android TV中) enter image description here

当onClick事件被触发时,我调用

v.animate().scaleX(1.2f).scaleY(1.2f).setDuration(500).start();

但是结果如下: enter image description here

它只能重叠位置低于自身的项目。
我应该怎么做才能重叠所有相邻的项目。提前致谢。
编辑
我已经尝试过:

v.bringToFront();

(v.getParent()).bringChildToFront(v);

但这两个都不行。

最佳答案

根据 aga 的 回答,我使用 ViewCompat.setElevation(View view, float elevation) 来支持 21 之前的 API,它工作起来很迷人。

static class ViewHolder extends RecyclerView.ViewHolder {

public ViewHolder(View root) {
// bind views
// ...

// bind focus listener
root.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
// run scale animation and make it bigger

ViewCompat.setElevation(root, 1);
} else {
// run scale animation and make it smaller

ViewCompat.setElevation(root, 0);
}
}
});
}
}

项目布局文件非常简单,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<TextView
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"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="@drawable/sl_live_item" />

关于android - 放大 RecyclerView 中的项目以重叠 2 个相邻的项目 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29487382/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com