安卓将卡片视图置于前景未能正常工作。

huangapple go评论69阅读模式
英文:

android bring to front not working on card view

问题

在安卓中,当尝试将一个视图置于卡片视图之前时,bringToFront() 方法无法正常工作。似乎卡片视图始终比其他视图具有更高的优先级。我尝试过同时使用 requestLayout()bringToFront(),但没有效果。有没有关于如何解决这个问题的想法?我尝试过使用 elevation,但在安卓 API 版本低于 21 的情况下不起作用。

view.post(() -> {
    view.setVisibility(View.VISIBLE);
    view.bringToFront();
    view.requestLayout();
});
英文:

In android bringToFront() not working when trying to bring a view to the front of a card view. It seems that the card view always has a higher priority than other views. I try requestLayout() plus bringToFront() too but it doesn't work. Is there any idea on how to solve this problem? I tried to use elevation but it does not work on android below API level 21.

view.post(() -> {
    view.setVisibility(View.VISIBLE);
    view.bringToFront();
    view.requestLayout();
});

答案1

得分: 1

最终的解决方案是使用FrameLayout。如果任何人想要在CardView前加载一个视图,必须将CardView放入FrameLayout中。没有FrameLayout,CardView会始终获得更高的高度和显示中的平移。

英文:

finally the solution was using FrameLayout. if anyone wants to load a view in front of a cardView it must put cardView in a frameLayout. without frameLayout cardView always get a higher elevation and translation in show

huangapple
  • 本文由 发表于 2020年9月29日 21:39:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/64120820.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定