0

I have successfully implemented emoticons in android as per this link.Problem is when the app is run on a higher density device,the selected emoticon appears too small.I have tried by changing the dimensionsof the drawable before display as follows

ImageGetter imageGetter = new ImageGetter() {
        public Drawable getDrawable(String source) {
            StringTokenizer st = new StringTokenizer(index, ".");
            Drawable d = new BitmapDrawable(getResources(),
                    emoticons[Integer.parseInt(st.nextToken()) - 1]);

            Log.i("tag", "" + Integer.parseInt(st.nextToken()));

            Drawable drawable = getResources().getDrawable(
                    getResources().getIdentifier(
                            "e" + (Integer.parseInt(st.nextToken()) - 1),
                            "drawable", getPackageName()));
            // d.setBounds(0, 0, d.getIntrinsicWidth(),
            // d.getIntrinsicHeight());
            d.setBounds(0, 0, 40, 40);
            return d;
        }
    };

But that doesnt help. The .png images are in the assets folder.Is there a way of having images of dirrent densities in the assets folder?Like the drawable-ldp,drawable-mdp ...?

mungaih pk
  • 1,809
  • 8
  • 31
  • 57
  • possible duplicate of [Android load drawable programatically and resize it](http://stackoverflow.com/questions/8837810/android-load-drawable-programatically-and-resize-it) – fpanizza Jun 05 '14 at 19:37
  • why not just put in the drawable folder then? – Budius Jun 05 '14 at 22:04

1 Answers1

0

Try the following:

DisplayMetrics metrics = getResources().getDisplayMetrics();
int densityDpi = (int)(metrics.density * 160f);

d.setBounds(0, 0, 10*densityDpi, 10*densityDpi);

Your code will now be taking the the density of your screen into account when sizing objects. This will help keep a consistent size amongst different devices.

Martin Konecny
  • 57,827
  • 19
  • 139
  • 159