安卓的FrameLayout不尊重绘制顺序 [英] Android: FrameLayout not respecting draw order

查看:562
本文介绍了安卓的FrameLayout不尊重绘制顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有排列成2×2网格4 SurfaceViews一个的FrameLayout。用户可以调整各的看法。

I have a FrameLayout with four SurfaceViews arranged in a 2x2 grid. The user can resize each of the views.

我想在他们的区域的顺序来绘制的意见,先等上绘制的最大视图。每个视图是调整的时候,我命令其区域的看法,并更新的FrameLayout:

I'd like the views to be drawn in order of their area, with the largest view drawn first and so on. Each time a view is resized, I order the views by their area, and update the FrameLayout:

public void reorderViews() {
        PlotView child1;
        PlotView child2;
        boolean swap = false;

        for(int i = 0; i < layout.getChildCount(); i++) {
            child1 = (PlotView) layout.getChildAt(i);
            for(int j = i + 1; j < layout.getChildCount(); j++) {
                child2 = (PlotView) layout.getChildAt(j);
                if(child1.area < child2.area) {
                    layout.removeViewAt(j);
                    layout.addView(child2, i);
                }
            }
        }

    }

这工作,在那的FrameLayout的孩子数组保存以正确的顺序的看法感。但是,重新排序后的意见继续原来的顺序(即在最初添加顺序)来绘制。

This works, in the sense that the FrameLayout's children array holds the views in the correct order. But after re-ordering, the views continue to draw in their original order (i.e. the order in which they were originally added).

我试过要求对布局的FrameLayout,对个别孩子的意见,对的FrameLayout的父视图。我也试过无效的一切。我重写的FrameLayout的OnDraw希望迫使正确的绘制顺序。没有去。

I've tried requesting layout on the FrameLayout, on the individual child views, on the FrameLayout's parent view. I've also tried invalidating everything. I've overridden the FrameLayout's onDraw hoping to force the correct draw order. No go.

的几点:我使用的FrameLayout而不是电网,因为我想更大的观点掩盖较小的观点,而不是具有较大视图推较小的观点不谈,作为在GridView控件的行为

A few points: I'm using FrameLayout rather than Grid because I'd like larger views to obscure smaller views, instead of having a larger view push a smaller view aside, as is the behaviour in GridView.

为了正确定位孩子的意见,我调整自己的利润,并设置其重力'顶'(它似乎并没有不管我用什么样的价值重力,只是只要重力设置的东西,利润率工作)。可能重力是问题?

In order to position the child views properly, I adjust their margins and set their gravity to 'top' (it doesn't seem to matter what value I use for gravity, just so long as gravity is set to something, margins work). Might the gravity be the issue?

另外,我敢肯定有重新排列的意见更有效的方式,但只有四道达尔公司,所以这个工程确定。

Also, I'm sure there's a more efficient way to reorder the views, but there's only four total, so this works ok.

推荐答案

SurfaceView 小部件使用正常的Andr​​oid的布局机制没有画出。相反,每个 SurfaceView 都有自己的,单独的窗口。我怀疑,当意见重新排列这些窗口不被重新排序。你正在试图做可能会为任何其他类型的小部件的工作。

SurfaceView widgets are not drawn using the normal Android layout mechanism. Instead, each SurfaceView gets its own, separate window. I suspect those windows are not being reordered when the views are reordered. What you're trying to do would probably work for any other kind of widget.

这篇关于安卓的FrameLayout不尊重绘制顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆