LayerDrawable自动更改背景

时间:2016-02-19 04:17:46

标签: android

LayerDrawable bgShape = (LayerDrawable) mActivity.getResources().getDrawable(R.drawable.treasure_box_bg);
if (bgShape != null) {
    ((ShapeDrawable) bgShape.getDrawable(1)).setPadding(0, mScreenWidth / 3, mScreenWidth, mWindowHeight);
    ViewsApiCompat.setBackground(mTreasureBoxView, bgShape);
}

1 个答案:

答案 0 :(得分:0)

ShapeDrawable biggerRectDrawable = new ShapeDrawable(new RectShape());
    biggerRectDrawable.getPaint().setColor(mActivity.getResources().getColor(R.color.treasure_box_content_bg));

    ShapeDrawable smallerRectDrawable = new ShapeDrawable(new RectShape());
    smallerRectDrawable.getPaint().setColor(mActivity.getResources().getColor(R.color.common_white));
    Drawable[] layers = {smallerRectDrawable, biggerRectDrawable};

    LayerDrawable layerDrawable = new LayerDrawable(layers);
    layerDrawable.setLayerInset(1, 0, mScreenWidth / 3, 0, 0);
    ViewsApiCompat.setBackground(mTreasureBoxView, layerDrawable);

问题解决了。宾果游戏。