1

我有一个特殊的用例,我有一个FrameLayout包含 2 个自定义视图的自定义。我会打电话MyWrapperFL的。我有另一个自定义视图,它在这个 custom 之外FrameLayout。所有这些都包含在一个基本的FrameLayout. 所以我有以下内容:

CustomView 1
MyWrapperFL
  CustomView 2
  CustomView 3

现在我想像这样更改视图的顺序:

CustomView 3 (top most)
CustomView 1
CustomView 2 (bottom most)

我尝试使用我创建的以下实用程序方法:

/**
   * Reorder the position of the views on their Z axis.
   * <br/>
   * The order of the views is important. The first in the list will be the top most view while the last in the list
   * will be the bottom most view.
   *
   * @param views
   *     The list of views which to reorder. Can be {@code null}.
   */
  private void updateViewsOrder(@Nullable View... views) {
    if (null == views) {
      // No views specified for reorder - exit early
      return;
    }
    List<View> viewList = Arrays.asList(views);

    int translationZ = viewList.size();
    for (View view : viewList) {
      if (null != view) {
        view.bringToFront();
        view.getParent().requestLayout();
        view.invalidate();
      }
    }
  }

但结果不是我们想要的。我得到以下结果,而不是预期的结果:

CustomView 1 (top most)
CustomView 3
CustomView 2 (bottom most)

我猜这是因为他们有不同的父母。谁能帮我这个?有没有办法做到这一点?

4

0 回答 0