Background Image Placement

后端 未结 4 992
不思量自难忘°
不思量自难忘° 2020-11-30 01:45

I\'m trying to set my root LinearLayout element (which is set to fill_parent in both dimensions) to have a background image which is always located in the lower left corner

4条回答
  •  我在风中等你
    2020-11-30 02:20

    If found an advantage doing this programatically: the image fits the layout instead of being bigger then it. No ideia why.

    The code:

    Bitmap bmp = BitmapFactory.decodeResource(getResources(),
                    R.drawable.image);
    BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
    bitmapDrawable.setGravity(Gravity.BOTTOM|Gravity.RIGHT);
    LinearLayout layout = (LinearLayout) findViewById(R.id.background_root);
    layout.setBackgroundDrawable(bitmapDrawable);
    

提交回复
热议问题