How does Gallery layout the size of each item in the Gallery

by Daniel Dreiberg » Thu, 14 May 2009 00:42:32 GMT


Sponsored Links
 Hi,
I have created a gallery and an adaptor for it. The getView() of the adaptor
get called but the view for some reason takes up whole screen of the
emulator instead of taking the minimum size.  Can you please tell me why is
that? Did Gallery measure the minimum side of the view of each item?

Thank you.

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Map overlay not drawing in beta 0.9. Why?

Hi all,

I'm running 0.9 in Eclipse 3.3/ADT.
I have a very stripped down one-class app (converted from m5) which
ought to be
presenting a map (that works ok) and then drawing an overlay (it
doesn't).
In onCreate(), a simple overlay (TOverlay) is created and added to
_mapView.getOverlays().
Lastly, mapUpdateHandler.sendEmptyMessage() is called, which should
invalidate the mapView,
and hence cause the overlay to be drawn.

I've copied the code below, and then copied the manifest.
The code has a few System.out.println's to determine flow of control.
All these appear in the LogCat output except the one in the overlay:
"TOverlay.draw".
At the very end I've copied the LogCat output.  One can see the
printlns:

09-09 15:18:06.332: INFO/System.out(695): o2:1
09-09 15:18:06.352: INFO/System.out(695): mUH:msg=101
09-09 15:18:06.352: INFO/System.out(695): mUH:101
09-09 15:18:06.352: INFO/System.out(695): o3: 1

But not the desired "TOverlay.draw"

Any suggestions will be greatly appreciated.
Thanks in advance,
Ken

-------------- Java ----------
package com.herenow.android.quester;

import java.util.List;

public class Quester extends MapActivity
{
        private static final double INIT_CENTER_LAT = 42.3908245;
        private static final double INIT_CENTER_LONG = -71.130993;
        private MapView _mapView;

    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        _mapView = new MapView(this, "dummyapikey");
        GeoPoint p = new GeoPoint((int) (INIT_CENTER_LAT * 1000000),
(int) (INIT_CENTER_LONG * 1000000));
        MapController mc = _mapView.getController();

        TOverlay tOver = new TOverlay(_mapView);
        List<Overlay> overlays = _mapView.getOverlays();
        overlays.add(tOver);

        mc.animateTo(p);
        mc.setZoom(15);
        setContentView(_mapView);

        mapUpdateHandler.sendEmptyMessage(101);
List<Overlay> o2 = _mapView.getOverlays();
System.out.println("o2:"+o2.size());
    }
    private Handler mapUpdateHandler
        = new Handler(){
                @Override
                public void handleMessage(Message msg) {
                        System.out.println("mUH:msg="+msg.what);
                    switch (msg.what) {
                          case 101:
                   //         _mapView.invalidate();
                            _mapView.postInvalidate();
                            System.out.println("mUH:101");
                                       break;
                             }
List <Overlay> o3 = _mapView.getOverlays();
System.out.println("o3: "+o3.size());
                     super.handleMessage(msg);
                }
            };

    public class TOverlay extends Overlay
    {
        private Paint plotPaint = new Paint();
        private MapView mapView;

        public TOverlay(MapView mapView){
                this.mapView = mapView;
                plotPaint.setColor(Color.BLUE);
        }

        public synchronized void draw(Canvas canvas, boolean b)
        {
            super.draw(canvas, mapView, b);
System.out.println("TOverlay.draw");

            int lat = (int)(INIT_CENTER_LAT*1E6);
                int lng = (int)(INIT_CENTER_LONG*1E6);
            GeoPoint geopoint = new GeoPoint(lat, lng);

            Point screenCoords = new Point();
            mapView.getProjection().toPixels(geopoint, screenCoords);
            canvas.drawCircle(screenCoords.x, screenCoords.y, 12,
plotPaint);
        }
    }

    public boolean isRouteDisplayed(){
        return false;
    }
}
--------------- Manifest -------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=" http://www.***.com/ ;
    package="com.herenow.android.quester">
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:icon="@drawable/icon">
        <activity android:name=".Quester" android:label="@string/
app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <uses-library android:name="com.google.android.maps" />
    </application>
</manifest>
-------------- LogCat Output-----------
09-09 15:38:59.813: DEBUG/dalvikvm(695): Calling exit(1)
09-09 15:38:59.843: INFO/ActivityManager(51): Process
com.herenow.android.quester (pid 695) has died.
09-09 15:38:59.853: DEBUG/Zygote(23): Process 695 exited cleanly (1)
09-09 15:38:59.863: INFO/WindowManager(51): WIN DEATH: Window{4347d300
com.herenow.android.quester/com.herenow.android.quester.Quester}
09-09 15:39:00.182: DEBUG/AndroidRuntime(709): >>>>>>>>>>>>>>
AndroidRuntime START <<<<<<<<<<<<<<
09-09 15:39:00.192: DEBUG/AndroidRuntime(709): CheckJNI is ON
09-09 15:39:00.353: DEBUG/AndroidRuntime(709): --- registering native
functions ---
09-09 15:39:00.363: INFO/jdwp(709): received file descriptor 19 from
ADB
09-09 15:39:01.052: DEBUG/PackageParser(51): Scanning package: /data/
app/vmdl38048.tmp
09-09 15:39:01.132: WARN/PackageManager(51): Attempt to re-install
com.herenow.android.quester without first uninstalling.
09-09 15:39:01.162: DEBUG/AndroidRuntime(709): Shutting down VM
09-09 15:39:01.162: DEBUG/dalvikvm(709): DestroyJavaVM waiting for non-
daemon threads to exit
09-09 15:39:01.162: INFO/dalvikvm(709): DestroyJavaVM shutting VM down
09-09 15:39:01.162: DEBUG/dalvikvm(709): HeapWorker thread shutting
down
09-09 15:39:01.172: DEBUG/dalvikvm(709): HeapWorker thread has shut
down
09-09 15:39:01.172: DEBUG/jdwp(709): JDWP shutting down net...
09-09 15:39:01.172: DEBUG/jdwp(709): +++ peer disconnected
09-09 15:39:01.172: INFO/dalvikvm(709): De{*filter*} has detached; object
registry had 1 entries
09-09 15:39:01.182: DEBUG/dalvikvm(709): VM cleaning up
09-09 15:39:01.192: DEBUG/dalvikvm(709): LinearAlloc 0x0 used 527204
of 4194304 (12%)
09-09 15:39:01.363: DEBUG/dalvikvm(51): GC freed 7240 objects / 405616
bytes in 207ms
09-09 15:39:01.483: DEBUG/AndroidRuntime(717): >>>>>>>>>>>>>>
AndroidRuntime START <<<<<<<<<<<<<<
09-09 15:39:01.483: DEBUG/AndroidRuntime(717): CheckJNI is ON
09-09 15:39:01.633: DEBUG/AndroidRuntime(717): --- registering native
functions ---
09-09 15:39:01.633: INFO/jdwp(717): received file descriptor 19 from
ADB
09-09 15:39:02.343: DEBUG/PackageParser(51): Scanning package: /data/
app/vmdl38049.tmp
09-09 15:39:02.413: DEBUG/PackageManager(51): Removing package
com.herenow.android.quester
09-09 15:39:02.413: DEBUG/PackageManager(51):   Activities:
com.herenow.android.quester.Quester
09-09 15:39:02.423: DEBUG/PackageManager(51): Scanning package
com.herenow.android.quester
09-09 15:39:02.433: ERROR/PackageManager(51): Package
com.herenow.android.quester has mismatched uid: 10008 on disk, 10015
in settings
09-09 15:39:02.433: INFO/PackageManager(51): /data/app/vmdl38049.tmp
changed; unpacking
09-09 15:39:02.443: INFO/dalvikvm(27): Opening files: input='/data/app/
vmdl38049.tmp' cache='/data/dalvik-cache/
[EMAIL PROTECTED]@[EMAIL PROTECTED]'
09-09 15:39:02.443: DEBUG/dalvikvm(27): DexInv: --- BEGIN
'vmdl38049.tmp' (bootstrap=0) ---
09-09 15:39:02.453: DEBUG/dalvikvm(27): DexInv: waiting for verify
+opt, pid=723
09-09 15:39:02.543: DEBUG/dalvikvm(723): Unable to resolve superclass
of Lcom/herenow/android/quester/Quester$TOverlay; (15)
09-09 15:39:02.553: DEBUG/dalvikvm(723): Link of class 'Lcom/herenow/
android/quester/Quester$TOverlay;' failed
09-09 15:39:02.553: DEBUG/dalvikvm(723): DexOpt: failed loading 'Lcom/
herenow/android/quester/Quester$TOverlay;'
09-09 15:39:02.553: DEBUG/dalvikvm(723): Unable to resolve superclass
of Lcom/herenow/android/quester/Quester; (12)
09-09 15:39:02.553: DEBUG/dalvikvm(723): Link of class 'Lcom/herenow/
android/quester/Quester;' failed
09-09 15:39:02.553: DEBUG/dalvikvm(723): DexOpt: failed loading 'Lcom/
herenow/android/quester/Quester;'
09-09 15:39:02.563: DEBUG/dalvikvm(723): VFY: unable to find class
referenced in signature (Lcom/herenow/android/quester/Quester;)
09-09 15:39:02.573: DEBUG/dalvikvm(723): VFY: unable to resolve static
method 25: Lcom/herenow/android/quester/Quester;.access$0 (Lcom/
herenow/android/quester/Quester;)Lcom/google/android/maps/MapView;
09-09 15:39:02.573: DEBUG/dalvikvm(723): VFY:  rejecting opcode 0x71
at 0x001d
09-09 15:39:02.583: DEBUG/dalvikvm(723): VFY:  rejected Lcom/herenow/
android/quester/Quester$1;.handleMessage (Landroid/os/Message;)V
09-09 15:39:02.583: DEBUG/dalvikvm(723): Verifier rejected class Lcom/
herenow/android/quester/Quester$1;
09-09 15:39:02.583: DEBUG/dalvikvm(723): DexOpt: not optimizing
unavailable class 'Lcom/herenow/android/quester/Quester$TOverlay;'
09-09 15:39:02.583: DEBUG/dalvikvm(723): DexOpt: not optimizing
unavailable class 'Lcom/herenow/android/quester/Quester;'
09-09 15:39:02.583: DEBUG/dalvikvm(723): DexOpt: load 24ms, verify
25ms, opt 1ms
09-09 15:39:02.593: DEBUG/dalvikvm(27): DexInv: --- END
'vmdl38049.tmp' (success) ---
09-09 15:39:02.593: DEBUG/PackageManager(51):   Activities:
com.herenow.android.quester.Quester
09-09 15:39:02.653: DEBUG/PackageManager(51): New package installed
in /data/app/com.herenow.android.quester.apk
09-09 15:39:02.743: DEBUG/AndroidRuntime(717): Shutting down VM
09-09 15:39:02.743: DEBUG/dalvikvm(717): DestroyJavaVM waiting for non-
daemon threads to exit
09-09 15:39:02.753: DEBUG/ActivityManager(51): Uninstalling process
com.herenow.android.quester
09-09 15:39:02.763: INFO/dalvikvm(717): DestroyJavaVM shutting VM down
09-09 15:39:02.763: DEBUG/dalvikvm(717): HeapWorker thread shutting
down
09-09 15:39:02.763: DEBUG/dalvikvm(717): HeapWorker thread has shut
down
09-09 15:39:02.763: DEBUG/jdwp(717): JDWP shutting down net...
09-09 15:39:02.763: DEBUG/jdwp(717): Got wake-up signal, bailing out
of select
09-09 15:39:02.763: INFO/dalvikvm(717): De{*filter*} has detached; object
registry had 1 entries
09-09 15:39:02.763: DEBUG/dalvikvm(717): VM cleaning up
09-09 15:39:02.763: DEBUG/dalvikvm(717): LinearAlloc 0x0 used 527204
of 4194304 (12%)
09-09 15:39:03.022: DEBUG/dalvikvm(51): GC freed 3617 objects / 197288
bytes in 223ms
09-09 15:39:03.202: DEBUG/AndroidRuntime(728): >>>>>>>>>>>>>>
AndroidRuntime START <<<<<<<<<<<<<<
09-09 15:39:03.202: DEBUG/AndroidRuntime(728): CheckJNI is ON
09-09 15:39:03.403: DEBUG/dalvikvm(91): GC freed 624 objects / 30648
bytes in 138ms
09-09 15:39:03.453: DEBUG/AndroidRuntime(728): --- registering native
functions ---
09-09 15:39:03.463: INFO/jdwp(728): received file descriptor 19 from
ADB
09-09 15:39:04.182: DEBUG/ActivityManager(51): Uninstalling process
com.herenow.android.quester
09-09 15:39:04.182: INFO/ActivityManager(51): Starting activity:
Intent { flags=0x10000000 comp={com.herenow.android.quester/
com.herenow.android.quester.Quester} }
09-09 15:39:04.222: INFO/ActivityManager(51): Start proc
com.herenow.android.quester for activity
com.herenow.android.quester/.Quester: pid=736 uid=10015 gids={3003}
09-09 15:39:04.252: DEBUG/AndroidRuntime(728): Shutting down VM
09-09 15:39:04.252: DEBUG/dalvikvm(728): DestroyJavaVM waiting for non-
daemon threads to exit
09-09 15:39:04.262: INFO/dalvikvm(728): DestroyJavaVM shutting VM down
09-09 15:39:04.262: DEBUG/dalvikvm(728): HeapWorker thread shutting
down
09-09 15:39:04.262: DEBUG/dalvikvm(728): HeapWorker thread has shut
down
09-09 15:39:04.262: DEBUG/jdwp(728): JDWP shutting down net...
09-09 15:39:04.262: DEBUG/jdwp(728): Got wake-up signal, bailing out
of select
09-09 15:39:04.262: INFO/dalvikvm(728): De{*filter*} has detached; object
registry had 1 entries
09-09 15:39:04.262: DEBUG/dalvikvm(728): VM cleaning up
09-09 15:39:04.293: DEBUG/dalvikvm(728): LinearAlloc 0x0 used 538516
of 4194304 (12%)
09-09 15:39:04.342: INFO/jdwp(736): received file descriptor 10 from
ADB
09-09 15:39:04.463: WARN/ActivityThread(736): Application
com.herenow.android.quester is waiting for the de{*filter*} on port
8100...
09-09 15:39:04.483: INFO/System.out(736): Sending WAIT chunk
09-09 15:39:04.503: INFO/dalvikvm(736): De{*filter*} is active
09-09 15:39:04.683: INFO/System.out(736): De{*filter*} has connected
09-09 15:39:04.693: INFO/System.out(736): waiting for de{*filter*} to
settle...
09-09 15:39:04.893: INFO/System.out(736): waiting for de{*filter*} to
settle...
09-09 15:39:05.102: INFO/System.out(736): waiting for de{*filter*} to
settle...
09-09 15:39:05.303: INFO/System.out(736): waiting for de{*filter*} to
settle...
09-09 15:39:05.505: INFO/System.out(736): waiting for de{*filter*} to
settle...
09-09 15:39:05.708: INFO/System.out(736): waiting for de{*filter*} to
settle...
09-09 15:39:05.913: INFO/System.out(736): waiting for de{*filter*} to
settle...
09-09 15:39:06.113: INFO/System.out(736): waiting for de{*filter*} to
settle...
09-09 15:39:06.316: INFO/System.out(736): de{*filter*} has settled (1346)
09-09 15:39:06.713: WARN/Maps_Persistence(736): Couldn't find file:  /
data/data/com.herenow.android.quester/files/DATA_Preferences
09-09 15:39:06.743: WARN/Maps_Persistence(736): Couldn't write
block:  /data/data/com.herenow.android.quester/files/DATA_Preferences
09-09 15:39:07.003: WARN/Maps_Persistence(736): Couldn't find file:  /
data/data/com.herenow.android.quester/files/DATA_Tiles
09-09 15:39:07.082: WARN/Maps(736): Couldn't restore map info, data ==
null
09-09 15:39:07.333: INFO/System.out(736): o2:1
09-09 15:39:07.423: INFO/System.out(736): mUH:msg=101
09-09 15:39:07.433: INFO/System.out(736): mUH:101
09-09 15:39:07.433: INFO/System.out(736): o3: 1
09-09 15:39:07.544: INFO/MapActivity(736): Handling network change
notification:CONNECTED
09-09 15:39:07.553: ERROR/MapActivity(736): Couldn't get connection
factory client
09-09 15:39:07.873: INFO/ActivityManager(51): Displayed activity
com.herenow.android.quester/.Quester: 3685 ms
09-09 15:39:10.033: ERROR/Database(51): Error inserting count=1
tag=HTTP_STATUS:AndroidHttpConnectionFactory/70597:200 sum=1.484 using
INSERT INTO stats(count, tag, sum) VALUES(?, ?, ?);
09-09 15:39:10.152: WARN/Maps_Persistence(736): Couldn't write
block:  /data/data/com.herenow.android.quester/files/DATA_Preferences
09-09 15:39:10.242: DEBUG/dalvikvm(736): GC freed 5309 objects /
307896 bytes in 58ms
09-09 15:39:11.202: ERROR/Database(51): Error inserting count=1
tag=HTTP_STATUS:AndroidHttpConnectionFactory/70597:200 sum=0.506 using
INSERT INTO stats(count, tag, sum) VALUES(?, ?, ?);
09-09 15:39:11.433: DEBUG/dalvikvm(736): GC freed 1333 objects / 95632
bytes in 80ms
09-09 15:39:11.553: ERROR/Database(51): Error inserting count=1
tag=HTTP_STATUS:AndroidHttpConnectionFactory/70597:200 sum=0.586 using
INSERT INTO stats(count, tag, sum) VALUES(?, ?, ?);
09-09 15:39:13.953: DEBUG/dalvikvm(117): GC freed 3 objects / 72 bytes
in 65ms
09-09 15:39:13.953: DEBUG/dalvikvm(91): GC freed 516 objects / 24744
bytes in 57ms


--~--~---------~--~----~------------~-------~--~----~

2. Image Button

Hi,
How to position the image buttons? I want to place 4 image buttons
with the text in one screen.Plz somebody help me



--~--~---------~--~----~------------~-------~--~----~

3. GoogleApps.apk

4. My Submission: PhoneIDE - Develop Android All in Phone

5. Offering widgets in the Application Market

6. orientation change bug with translucent activities

7. Why the WebView's Zoom slider can be showed?