关于View的属性

自定义动态设置View的大小属性


使用LayoutParams来设置view的宽高.


int textLen = AddShopActivity.mCategoryItemNames1[type][textPos].length();
        final int dimension = (int) (getResources().getDimension(R.dimen.text_size));
        int left = dimension * textLen
                + (int) (getResources().getDimension(R.dimen.rl_left));
        RelativeLayout.LayoutParams lp2 = new LayoutParams(left
                + (int) (getResources().getDimension(R.dimen.rl_right)),
                (int) (getResources().getDimension(R.dimen.rl_height)));
        lp2.setMargins(0, (int) (getResources().getDimension(R.dimen.rl_top)),
                0, (int) (getResources().getDimension(R.dimen.rl_top)));
        mRL01.setLayoutParams(lp2);
        mDeleteBt = (Button) mRLMain.findViewById(R.id.deletebt);
        MarginLayoutParams marginsParams = new MarginLayoutParams(
                mDeleteBt.getLayoutParams());
        marginsParams.setMargins(left, 0, 0, 0);
        RelativeLayout.LayoutParams lp = new LayoutParams(marginsParams);


ViewGroup内部View的图层关系

bar.bringToFront();

在辛显龙Blog中是这样解释的: Android中的ViewGroup是通过一个Array来保存其Children,当调用某个childView的bringToFront时,是将该childView放在其Parent的Array数组的最后,ViewGroup的dispatchDraw在draw时是按照Array从前往后依次调用drawChild的,这样最后一个childView就在最前面了。