放大 RecyclerView 中的 Item 以重叠 2 个相邻的 Android 项目 [英] Scale up Item in RecyclerView to overlaps 2 adjacent items Android
问题描述
我将 RecyclerView 与 GridLayoutManager 一起使用.我想要实现的目标是当我点击一个项目时,它会放大并重叠相邻的项目.就像下图(在Android TV中)
I'm using RecyclerView with GridLayoutManager. The goal I want to achieve is when I click on an item, It'll scale up and overlaps the adjacent items. Just like the picture below (in Android TV)
当onClick事件被触发时,我调用
When the onClick event is triggered, I call
v.animate().scaleX(1.2f).scaleY(1.2f).setDuration(500).start();
但结果如下:
它只能与位置低于自身的项目重叠.
我该怎么做才能重叠所有相邻的项目.提前致谢.
编辑
我已经试过了:
It can overlaps only items that has position lower than itself.
What should I do to overlaps all of the adjacent items. Thanks in advance.
EDIT
I already tried:
v.bringToFront();
或
(v.getParent()).bringChildToFront(v);
但它们都不起作用.
推荐答案
根据aga的回答,我使用ViewCompat.setElevation(View view, floatlevation)来支持API21 岁之前,它就像一个迷人的人.
According aga's answer, i use ViewCompat.setElevation(View view, float elevation) to support API prior to 21, It works like a charming.
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);
}
}
});
}
}
项目布局文件非常简单,如下所示:
The item layout file is very simple like below:
<?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" />
这篇关于放大 RecyclerView 中的 Item 以重叠 2 个相邻的 Android 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!