如何在代码中使用毕加索设置背景图像

2024-04-30

我知道毕加索将图像加载到 imageview 等中,但如何使用毕加索设置布局背景图像?

My code:

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativelayout);
        relativeLayout.setBackgroundResource(R.drawable.table_background);
        Picasso.with(MainActivity.this)
                .load(R.drawable.table_background)
                .resize(200, 200)
                .into(relativeLayout);
        return relativeLayout;
    }

我这里给出的任何错误都表明无法解决。我有一个 ScrollView 和相关布局。


使用Picasso的回调

    Picasso.with(getActivity()).load(R.drawable.table_background).into(new Target(){

  @Override
  public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
     mainLayout.setBackground(new BitmapDrawable(context.getResources(), bitmap));
  }

  @Override
  public void onBitmapFailed(final Drawable errorDrawable) {
      Log.d("TAG", "FAILED");
  }

  @Override
  public void onPrepareLoad(final Drawable placeHolderDrawable) {
      Log.d("TAG", "Prepare Load");
  }      
})

UPDATE:

请检查this https://stackoverflow.com/a/31464960/3967525也如@OlivierH 在评论中提到的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在代码中使用毕加索设置背景图像 的相关文章

随机推荐