首页 > 移动平台 > 详细

android控件显示顺序控制

时间:2014-10-24 13:01:43      阅读:366      评论:0      收藏:0      [点我收藏+]

在android中如果首先在xml中静态添加了一个控件,剩下的控件都是通过addView动态添加,那么如果有控件覆盖的情况(比如说使用FrameLayout或者RelativeLayout),先加入得控件就会被后加入得控件覆盖。

在View类中有这样一个方法 bringToFront ,它得注释如下:

     /**

     * Change the view‘s z order in the tree, so it‘s on top of other sibling

     * views. This ordering change may affect layout, if the parent container

     * uses an order-dependent layout scheme (e.g., LinearLayout). Prior

     * to {@link android.os.Build.VERSION_CODES#KITKAT} this

     * method should be followed by calls to {@link #requestLayout()} and

     * {@link View#invalidate()} on the view‘s parent to force the parent to redraw

     * with the new child ordering.

     *

     * @see ViewGroup#bringChildToFront(View)

     */

我们可以看到,这个方法可以改变ViewGroup内子控件在Z轴坐标得顺序,使得当前控件在所有兄弟控件得最前面,同时在4.4之前得版本,还需要它的父控件调用requestLayout()和invalidate()来重新绘制子控件的顺序。

而且要注意的一点是,需要在所有控件都加载完之后才能调用 bringToFront()来设置指定控件的顺序,否则后加载的控件还是可能覆盖你想要上提的控件的。

这样我们就可以通过这个方法来排列子控件的覆盖顺序啦。

android控件显示顺序控制

原文:http://blog.csdn.net/goodlixueyong/article/details/40425387

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!