How to fix hit area after scaling

by Jonathan » Wed, 12 May 2010 03:52:59 GMT

Sponsored Links
 I am scaling the canvas of a linear layout on draw, but this throws
off all the hit areas of my views inside of this layout. They respond
as if there was no scaling taking place. What do I have to do to get
themselves to re-register their hit areas?




How to fix hit area after scaling

by Jason Tomlinson » Wed, 12 May 2010 20:55:13 GMT

 You need to scale your hit areas to match the canvas scaling.  If you
zoom in 2x on the canvas your hit area is now twice the size likewise
if you zoomed out 2x then your hit area is half the size.


Sponsored Links

How to fix hit area after scaling

by Jonathan » Thu, 13 May 2010 02:03:29 GMT

 Right, thats what I am trying to figure out how to do. I currently
don't know how to separate a hit area from an actual view.

It would make sense to me if there was some function needed to be
called that would then figure out the new bounds of the views and
change their hit areas appropriately. I am calling invalidate on the
parent layout, but that doesn't seem to do anything to the views
themselves. I'll try calling it on each child and see if that makes a

> >

How to fix hit area after scaling

by Jonathan » Thu, 13 May 2010 07:12:20 GMT

 Just in case anybody else wants to accomplish this, all you have to do
is override your child view's getHitRect method to account for your
parent view's scale transformation.

I'm not sure why the base view class doesn't do this automatically,
but I'm sure there is a reason.

> > >

Other Threads

1. Strange issue - AutoCompleteTextView does not show results - CursorAdapter


      I have been trying to get my head around this issue, but can't
figure out. I have an AutoCompleteTextView which I am populating from
a custom adapter that extends CursorAdapter. The data source for the
cursor adapter is a table(columns : name and _id) in my database. I
have put debug statements in every method in My Custom Adapter class
that extends CursorAdapter, but none of the methods that I have
overridden like newView(), convertToString(), bindView() get called,
EXCEPT runQueryOnBackgroundThread() which gets called as I type my
input into the text view. Here is my code for your reference :

Inner Class :

    private class myCursorAdapter extends CursorAdapter
          Context context = null;
          private int columnIndex;

                        public myCursorAdapter(Context context, Cursor c, int 
col) {
                                super(context, c);
                                this.columnIndex = col;

            public void bindView(View view, Context context, Cursor
cursor) {
                Log.d("MainActivity", " bindView:"+cursor.getString
                ((TextView) view).setText(cursor.getString

            public String convertToString(Cursor cursor) {
                Log.d("MainActivity", " convertToString:"+cursor.getString
                return cursor.getString(columnIndex);

            public View newView(Context context, Cursor cursor,
ViewGroup parent)
                Log.d("MainActivity", "
                final LayoutInflater inflater = LayoutInflater.from
                final TextView view = (TextView) inflater.inflate(
parent, false);
                return view;

            public Cursor runQueryOnBackgroundThread(CharSequence
                    if (constraint != null){
                        return MainActivity.this.getItemsAsCursor
                        return MainActivity.this.getItemsAsCursor("All");

This is how I instantiate and set the adapter (From a class that
extends ListActivity) :

        Cursor cursor = getItemsAsCursor("All");
        myCursorAdapter adapter = new myCursorAdapter
(this.getApplicationContext(), cursor, 0);
        AutoCompleteTextView textView = (AutoCompleteTextView) findViewById

Am I doing something wrong? Any help is highly appreciated.


2. Android Unit Tests - VerifyError

I am tying to run AndroidTests.apk but I am receiving VerifyErrors.
Please Advise

I installed AndroidTests.apk using adb install.

Command Line Output:

$ adb shell am instrument -w
INSTRUMENTATION_RESULT: longMsg=java.lang.VerifyError:

LogCat Output:

D/AndroidRuntime(  270):
D/AndroidRuntime(  270): >>>>>>>>>>>>>> AndroidRuntime START
D/AndroidRuntime(  270): CheckJNI is OFF
D/AndroidRuntime(  270): --- registering native functions ---
D/ActivityManager(   54): Uninstalling process
I/ActivityManager(   54): Start proc for added
application pid=276 uid=10025 gids={3003}
D/dalvikvm(  276): GC freed 5340 objects / 386784 bytes in 133ms
D/dalvikvm(  276): GC freed 7860 objects / 630784 bytes in 131ms
I/TraceTest(  276): Loading trace_test native library...
W/TraceTest(  276): Could not load trace_test native library
W/dalvikvm(  276): VFY: unable to resolve interface method 131:
Landroid/content/pm/IPackageManager;.freeStorageAndNotify (JLandroid/
W/dalvikvm(  276): VFY:  rejecting opcode 0x72 at 0x0015
W/dalvikvm(  276): VFY:  rejected Lcom/android/unit_tests/
AppCacheTest;.invokePMFreeApplicationCache (J)Z
W/dalvikvm(  276): Verifier rejected class Lcom/android/unit_tests/
D/AndroidRuntime(  276): Shutting down VM
W/dalvikvm(  276): threadid=3: thread exiting with uncaught exception
E/AndroidRuntime(  276): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime(  276): java.lang.VerifyError:
E/AndroidRuntime(  276):        at java.lang.Class.getDeclaredConstructors
(Native Method)
E/AndroidRuntime(  276):        at java.lang.Class.getConstructors
E/AndroidRuntime(  276):        at android.test.suitebuilder.TestGrouping
E/AndroidRuntime(  276):        at android.test.suitebuilder.TestGrouping
E/AndroidRuntime(  276):        at android.test.suitebuilder.TestGrouping
E/AndroidRuntime(  276):        at
E/AndroidRuntime(  276):        at
E/AndroidRuntime(  276):        at
E/AndroidRuntime(  276):        at
E/AndroidRuntime(  276):        at
E/AndroidRuntime(  276):        at
E/AndroidRuntime(  276):        at
E/AndroidRuntime(  276):        at$2500
E/AndroidRuntime(  276):        at$H.handleMessage
E/AndroidRuntime(  276):        at android.os.Handler.dispatchMessage
E/AndroidRuntime(  276):        at android.os.Looper.loop(
E/AndroidRuntime(  276):        at
E/AndroidRuntime(  276):        at java.lang.reflect.Method.invokeNative
(Native Method)
E/AndroidRuntime(  276):        at java.lang.reflect.Method.invoke
E/AndroidRuntime(  276):        at
E/AndroidRuntime(  276):        at
E/AndroidRuntime(  276):        at dalvik.system.NativeStart.main(Native
I/Process (   54): Sending signal. PID: 276 SIG: 3
I/dalvikvm(  276): threadid=7: reacting to signal 3
W/ActivityManager(   54): Error in app running
instrumentation ComponentInfo{
W/ActivityManager(   54):
W/ActivityManager(   54):   java.lang.VerifyError:
D/ActivityManager(   54): Uninstalling process
D/ActivityManager(   54): Force removing process ProcessRecord
{43164a28} (


3. SDK 1.5 Error

4. Chat w/ Android App Developer Pixelpipe on Friday 2pm PST

5. How to get text at touch points

6. Question about ExpandableList and SimpleExpandableListAdapter

7. Phone call recorder