android studio中的setBackgroundDrawable()已弃用。有没有其他方法来分配位图和设置为relativeLayout的背景?

时间:2016-01-26 13:26:40

标签: android bitmap relativelayout deprecated

使用位图分配relativeLayout背景的任何想法?

    RelativeLayout bg = (RelativeLayout) findViewById(R.id.relativeLayout);
    bg.setBackgroundDrawable();// deprecated

4 个答案:

答案 0 :(得分:2)

改为使用setBackground()

RelativeLayout bg = (RelativeLayout) findViewById(R.id.relativeLayout);
bg.setBackground(drawable);

答案 1 :(得分:1)

RelativeLayout bg =(RelativeLayout)findViewById(R.id.relativeLayout);

 1) bg.setBackgroudDrawable(Drawable);
 2) bg.setBackgroundResource(int);

答案 2 :(得分:0)

    RelativeLayout bg = (RelativeLayout) findViewById(R.id.relativeLayout);
    Drawable d = new BitmapDrawable(bm);
    bg.setBackgroundDrawable(d);

BitmapDrawable()已被弃用,我仍然无法将位图设置为relativeLayout的backgorund

答案 3 :(得分:0)

使用

bitmap //Your bitmap Image
RelativeLayout bg = (RelativeLayout) findViewById(R.id.relativeLayout);
BitmapDrawable ob = new BitmapDrawable(getResources(), bitmap)
bg.setBackground(ob);