Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6038439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:13:18+00:00 2026-05-23T06:13:18+00:00

I need to paint an overlay image onto a SeekBar in my ListView rows.

  • 0

I need to paint an overlay image onto a SeekBar in my ListView rows. This isn’t too hard to do and the code in this question accomplishes that by painting the row number in a bitmap and placing it as the progress drawable.

The problem that I am having is that this only works one time. When the view is recycled to be used for another row, the drawable disappears.

enter image description here

The first 10 views (positions 0 through 9) worked. Everything after that fails. There is no error or exception. Android just stops drawing that layer. If I scroll down and then back up, none of them work (as they have all been recycled).

How do I get Android to always draw this overlayed image? I imagine there is some sort of caching or invalidation that I need to perform, but I just don’t know what it is yet.

public class ViewTest extends ListActivity {
    // replace the progress drawable with my custom drawable
    public void setSeekBarOverlay(SeekBar seekBar, String overlayText) {
        Bitmap bitmap = Bitmap.createBitmap(100, 12, Bitmap.Config.ARGB_4444);
        new Canvas(bitmap).drawText(overlayText, 10, 12, new Paint());

        Drawable d = new BitmapDrawable(bitmap);
        ((LayerDrawable) seekBar.getProgressDrawable()).setDrawableByLayerId(android.R.id.progress, d);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setListAdapter(new ListAdapter() {

            // return the view. Recycle them if possible.
            public View getView(int pos, View v, ViewGroup vg) {
                if (v == null) {
                    v = View.inflate(ViewTest.this, R.layout.seekbar, null);
                }

                String s = String.valueOf(pos);
                ((TextView) v.findViewById(android.R.id.text1)).setText(s);
                setSeekBarOverlay((SeekBar) v.findViewById(R.id.seekbar), s);
                return v;
            }

            ... cut ...
        });
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<ListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

seekbar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeight">

    <TextView
        android:id="@android:id/text1"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_height="wrap_content" />
    <SeekBar
        android:id="@+id/seekbar"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content" />
</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:13:18+00:00Added an answer on May 23, 2026 at 6:13 am

    This is a tough one that I don’t think will get much traffic, so I’m going to answer it myself since I found the solution.

    Another SO question/answer, Android ProgressBar.setProgressDrawable only works once?, got me halfway there but the solution didn’t work for me. In the other question, the code was trying to replace the entire progressDrawable (setProgressDrawable()). I’m not doing that here as I’m just updating a layer in the existing progressDrawable. After some playing around, with similar approaches, I found something that worked. You have to get the bounds of the drawable that is being updated (in this case, one of the layers) and set the bounds later.

    Seems like a bug in the platform, but this workaround seems to make it work. Hope this helps someone else someday.

    public void setSeekBarOverlay(SeekBar seekBar, String overlayText) {
        LayerDrawable layerDrawable = (LayerDrawable) seekBar.getProgressDrawable();
        Drawable overlayDrawable = layerDrawable.findDrawableByLayerId(android.R.id.progress);
        Rect bounds = overlayDrawable.getBounds();
    
        Bitmap bitmap = Bitmap.createBitmap(100, 12, Bitmap.Config.ARGB_4444);
        new Canvas(bitmap).drawText(overlayText, 10, 12, new Paint());
        overlayDrawable = new BitmapDrawable(bitmap);
    
        overlayDrawable.setBounds(bounds);
        layerDrawable.setDrawableByLayerId(android.R.id.progress, overlayDrawable);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am need paint my image. I'm trying use JQuery in here this link:
I have a BufferedImage with an IndexColorModel. I need to paint that image onto
Do we need to do double buffering in BlackBerry while rendering our paint code
I need to overlay some textures onto a video in a layered fashion (i.e.
To reproduce this issue, please create a 2x2 pixel black image in Microsoft Paint,
I need to go over all radio buttons of the form and paint the
I need a view (infoView) to be displayed as an overlay on top of
I'm trying to overlay an image with some text using PyObjC, while striving to
Can someone show me how to dynamically overlay an image (an icon in my
I have this two strings of equal length, which I need to compare. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.