Background Image Placement

后端 未结 4 988
不思量自难忘°
不思量自难忘° 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:26

    My answer is just an update of above answers If you are using XML for background, it may occur problem in aspect ratio

    so use this code

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

    Gravity.Fill_HORIZONTAL will fit with width of layout on which you are applying background you can also mention this in XML file but as i said it will occur issue of Image Ratio

提交回复
热议问题