This is related to my last post on a possible bug in TextView, but I
don't think that's my problem. I was reading the TextView source code
to try to get a handle on this bug I'm seeing.

I'm using a PaintDrawable that I get by defining it as described in
this article:

http://developer.android.com/intl/de/guide/topics/resources/available-resources.html

here's my definition file res/values/colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
        <color name="red_text_background">#FF0000</color>
        <color name="orange_text_background">#FFA000</color>
        <color name="normal_text_background">#FFFFFF</color>
        <drawable name="red_drawable">@color/red_text_background</drawable>
        <drawable name="orange_drawable">@color/orange_text_background</
drawable>
        <drawable name="normal_drawable">@color/normal_text_background</
drawable>
</resources>

I'm transitioning to the drawables from setting background colors.
That's why things are duplicated.

Here's how I'm trying to set a TextView to have some kind of drawable
that is separate from the text:

        private void setTextView(TextView tv, int val, int rlimit, int
ylimit) {
                final float scale = 
this.getResources().getDisplayMetrics().density;
                tv.setText(String.valueOf(val));
                int r;
                Drawable t;
                if(val > rlimit) {
                        r = R.drawable.red_drawable;
                        t = mRedDrawable;
                } else if (val > ylimit) {
                        r = R.drawable.orange_drawable;
                        t = mOrangeDrawable;
                } else {
                        r = R.drawable.normal_drawable;
                        t = mNormalDrawable;
                }
                t.setBounds(0, 0, (int)((HUH * scale) + 0.5f), (int)((HUH * 
scale) +
0.5f));
                // t.setBounds(0, 0, tv.getWidth(), (int)((DPADDING * scale) +
0.5f));
                // t.setBounds(0, 0, 1, tv.getHeight());

                Log.d(TAG, String.format("Intrisic height = %1$d, width = %2$d",
t.getIntrinsicHeight(), t.getIntrinsicWidth()));
                tv.setCompoundDrawablePadding((int)(DPADDING * scale + 0.5f));
                // tv.setCompoundDrawablesWithIntrinsicBounds(0, r, 0, 0);
                // tv.setCompoundDrawables(null, t, null, null);
                tv.setCompoundDrawablesWithIntrinsicBounds(null, t, null, null);
        }

No matter what I set the bounds to, or how I set the drawables (you
can see the different attempts in the commented out sections), I don't
see what I expect.

What I see is just as if I called setBackgroundDrawable() on the
TextView, plus added pixels of the same color, either on the top,
right, left or bottom.

Can someone explain what is wrong?

Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to