Skip to content

Instantly share code, notes, and snippets.

View alexfu's full-sized avatar

Alex Fu alexfu

View GitHub Profile
@alexfu
alexfu / DontScaleMe.java
Created February 4, 2014 03:41
Prevent your BitmapDrawables from scaling when using setBackground/setBackgroundDrawable. This is usually desired when you want to set an image as your background.
public class DontScaleMe extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.alayout);
ViewGroup parent = findViewById(R.id.root);
Bitmap bitmap = obtainBitmapFromSomewhere();
// This will scale your Bitmap to fit it's bounds.
parent.setBackground(new BitmapDrawable(getResources(), bitmap));