How to bring a view to front without calling bringToFront()?

て烟熏妆下的殇ゞ 提交于 2019-11-29 14:03:16

apparently I missed the android:clipChildren="false" property in GridView. It solves my problem.

Have you tried making the View focusable and just calling requestFocus()?

Calling bringToFront() changes the ordering in the GridView. Try creating an ImageView with an image of the view you want to animate and animate that instead.

Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
final ImageView imageView = new ImageView(getActivity());
imageView.setImageBitmap(bitmap);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(view.getWidth() , view.getHeight());
imageView.setLayoutParams(params);
rootview.addView(imageView);

Add an animation listener to your animation and remove the ImageView at the end of the animation.

From API 21 you can call:

view.setZ(float)
JPhi Denis

If you target API above 21, you can simply add the attribute android:translationZ="xxx dp" to your XML.

Please note that if you add elevation in views like cardview, you go into the Z axis. And if you want a view come to foreground using this way, you just have to make it higher than the elevation you set.

Example : 6 dp elevation in cardview will require a 7dp in the attribute translationZ of the view you want foreground.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!