Record about selector and layer-list

layerlist

1.多张图片可以叠加在一起做为某个ImageView的背景。

可以在xml或代码中实现:

xml中实现:


    
    

    

效果如下:

Record about selector and layer-list_第1张图片
xml实现效果
在代码中实现:
    private void practiceLayerList() {
        ImageView img = (ImageView) findViewById(R.id.layer_list_img);

        Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
        Drawable[] drawables = new Drawable[3];
        drawables[0] = new PaintDrawable(Color.BLACK);
        drawables[1] = new PaintDrawable(Color.GREEN);
        drawables[2] = new BitmapDrawable(getResources(), bm);

        LayerDrawable layerDrawable = new LayerDrawable(drawables);
        layerDrawable.setLayerInset(1, 20, 20, 20, 20);
        layerDrawable.setLayerInset(2, 40, 40, 40, 40);

        /*
        * layerlist可以在xml中实现,也可以在代码中设置
        * 代码中使用layerDrawable
        * layerDrawble.setLayerInset()
        * 有五个int类型的参数,第一个表示drawable数组的下标
        * 剩下四个分表表示left,top,right,bottom方向向内的padding
        * */

        img.setBackground(layerDrawable);
    }

关于selector的记录:




    

        

            

            

            

            

            

        

    

    

        

            

            

            

        

    


实现效果如下:

Record about selector and layer-list_第2张图片
正常状态
Record about selector and layer-list_第3张图片
按下状态

你可能感兴趣的:(Record about selector and layer-list)