Android drawing - Background caching
Quick question - I'm having control that's extending LinearLayout and I'm overriding it's onPaint method like this
@Override protected void onDraw(Canvas canvas) { super.dispatchDraw(canvas); _background.draw(canvas); _object1.draw(canvas); _object2.draw(canvas); _object3.draw(canvas); // etc... }
Every 40ms I invoke postInvalidate() in background and onPaint gets called on UI thread. The problem is _background.draw is taking over 80% of my drawing time.
So - is it possible to somehow cache background and not redraw it every time?
Asked by: Blake607 | Posted: 20-01-2022
Answer 1
You can specify a region to postInvalidate()
to control the area that gets redrawn.
Similar questions
android - How to set background color of a View
I'm trying to set the background color of a View (in this case a Button).
I use this code:
// set the background to green
v.setBackgroundColor(0x0000FF00 );
v.invalidate();
It causes the Button to disappear from the screen. What am I doing wrong, and what is the correct way to change the background color on any View?
Thanks.
Android Widget Text Background
I have an app with a widget but I am having some difficulty with the layout of the widget.
The basic idea if the widget should look like an icon and have a little text tag under it like any other icon on the desktop.
I found one example which uses an android:background for the TextView and uses a drawable XML:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid...
How do I change the background of an Android tab widget?
My class extends extends TabActivity
TabHost mTabHost = getTabHost();
TabHost.TabSpec tab1 =mTabHost.newTabSpec("tab1");
TabHost.TabSpec tab2 =mTabHost.newTabSpec("tab2");
tab1 .setIndicator("title tab1");
tab2 .setIndicator("title tab2");
mTabHost.addTab(tab1);mTabHost.addTab(tab2);
TabHost.setCurrentTab(0 or 1)
Can anybody guide me how do I change the background image or color of sel...
android - Set title background color
In my android application I want the standard/basic title bar to change color.
To change the text color you have setTitleColor(int color), is there a way to change the background color of the bar?
java - I want my app to run things in the background, even when the user is donig other things on his Android
What should I look at to get started?
Is it Timer? http://developer.android.com/reference/java/util/Timer.html
Or am I missing something else?
android - Background in tab widget ignore scaling
I tried to use a background (480x320) for my tab content. Using a xml as drawable, I should be able to scale the image. This works fine outside the tabhost/tabactivity. If I try to use it inside the tabcontent, the scaleType doesn't work. He ignores every scaleType I tried.
tabcontent:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/a...
android - How to add padding for background image
I have a LinearLayout which has a background image (a 9 patched png file).
How can I add padding to left and right so that the background image does not take up the whole width? I have tried android:paddingLeft and android:paddingRight, but that does not change anything.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation...
android - Loading a Browser Page in the Background
I have a tabbed interface (one activity per tab) where one tab will be a browser view displaying a webpage. The application loads in a different activity / view, but I want it to begin to download the webpage in the background as soon as the app launches, before the user ever clicks on that tab and initiates that activity.
How can I do this?
Thanks!
-S
android - How to make an app's background image repeat
I have set a background image in my app, but the background image is small and I want it to be repeated and fill in the whole screen. What should I do?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg"
android:tileMode="repe...
Change background color of android menu
This question already has answers here:
android - How to avoid the ugly "boxes" when child views in a View has another color than the background (stateful drawables for example)
I have a simple ListView and on that ListView I have placed a number of custom defined Views. The CustomView has ImageView and two TextViews.
The CustomView also has a "stateful drawable" as background, so that the background image (a 9-patch) changes if you press the Row in the ListView. When pressing the Row, the background image changes to a Red-ish thing.
The problem is that when the background ...
android - how to start activity when the main activity is running in background?
I created an application which enables the user to set whether he wants to receive notification while the application runs in background mode. If the notifications are enabled an activity should be started (the dialog should appear on the screen).
I tried to enabled it the following way:
@Override
public void onProductsResponse(List<Product> products) {
this.products = products;
mobool...
android - View on press onpress: Change background color on press? How do I show that the View is being pressed?
I have, for the time being, a custom view with a 9-patch image as a border.
That custom view is placed three times in a LinearLayout, so it looks like this:
+------------------------+
| CustomView |
+------------------------+
| CustomView |
+------------------------+
| CustomView |
+------------------------+
I have attached a click event listener...
android - how to structure my app to run in background
I am new to Android, and I need some advices for start up.
I want to build an application, which will show up, when the user gets into some hot situation.
By hot situation I mean:
the GPS/cell coordinates are in known zone;
known Bluetooth device detected;
known Wi-Fi network detected;
weather info has change;
I see something running in backgroun...
audio - Android - how to do background threading properly?
Was wondering if anyone could help me on background threading on Android.
I have a piece of code that records from the mic of the device and then plays back what it records through the ear piece(on 1.5).
I am trying to run it in a thread but have been unsuccessful in getting it to run as a background thread.
Currently it runs and locks up the activity so that all thats happening is the thread is ru...
android - How to set background color of a View
I'm trying to set the background color of a View (in this case a Button).
I use this code:
// set the background to green
v.setBackgroundColor(0x0000FF00 );
v.invalidate();
It causes the Button to disappear from the screen. What am I doing wrong, and what is the correct way to change the background color on any View?
Thanks.
Android Widget Text Background
I have an app with a widget but I am having some difficulty with the layout of the widget.
The basic idea if the widget should look like an icon and have a little text tag under it like any other icon on the desktop.
I found one example which uses an android:background for the TextView and uses a drawable XML:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid...
How do I change the background of an Android tab widget?
My class extends extends TabActivity
TabHost mTabHost = getTabHost();
TabHost.TabSpec tab1 =mTabHost.newTabSpec("tab1");
TabHost.TabSpec tab2 =mTabHost.newTabSpec("tab2");
tab1 .setIndicator("title tab1");
tab2 .setIndicator("title tab2");
mTabHost.addTab(tab1);mTabHost.addTab(tab2);
TabHost.setCurrentTab(0 or 1)
Can anybody guide me how do I change the background image or color of sel...
android - Set title background color
In my android application I want the standard/basic title bar to change color.
To change the text color you have setTitleColor(int color), is there a way to change the background color of the bar?
Run a service in the background forever..? Android
I am doing a Battery Consuming research on the Android phone. I want to run a Battery Check every 10 min till the battery totally dies. I have been having problems to make it work.
At my first try, I use a timer in a service class, and schedule the battery check every 10 mins. But soon I found that the service got paused when the screen goes off.
Then I try to use AlarmService, I use a alarm call to wake my...
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android