Arbitrary positioning icon on a View

by Eric » Tue, 24 Nov 2009 10:32:54 GMT


Sponsored Links
 Hey all,

I'm trying to figure out how to mimic the "badge" functionality of an
iPhone app...in particular, I've got a gridview that has several
icons, and based on the result of an AsyncTask, I'd like to position a
"new" badge hovering over one of the icons.  I've got the icon showing
up using Activity.addContentView but there don't seem to be any
ViewGroup.LayoutParams attributes to control an x/y position where the
new view should be displayed.  The options as I see them:

1) FrameLayout (also no support for offset that I can see)
2) RelativeLayout (can't figure out how to dynamically add a new
ImageView)
3) Create a large, mostly transparent png to handle the offset non-
programmatically
4) Use AbsoluteLayout to specify pixel offsets.

Any other options I'm missing?  I'd really like to avoid using #3
(clunky) or #4 (deprecated)...any way to get #1 or #2 working?  Or is
there another option I'm missing?

--



Arbitrary positioning icon on a View

by Nithin » Tue, 24 Nov 2009 14:21:06 GMT


 Hi Eric,

Try offsetLeftAndRight() and offsetTopAndBottom() on the imageView, to
position it accordingly in the layout. But it is temporary only. Both
these offset will reset in the next layout pass.

Thanks





--


Sponsored Links


Arbitrary positioning icon on a View

by appforce.org » Tue, 24 Nov 2009 15:44:48 GMT


 Hi Eric,

Have you considered changing your adapter to provide the ImageView-s
nested in RelativeLayout-s?

This will let you do getParent().addView() on you icons.

--



Arbitrary positioning icon on a View

by Eric » Wed, 25 Nov 2009 07:58:52 GMT


 Thanks for the replies, guys.  I ended up using View.setPadding (the
temporary nature of the offset* methods was a bit too transitory for
my needs) to set a left/top padding on the ImageView, and it works
like a charm.




--



Arbitrary positioning icon on a View

by Dianne Hackborn » Wed, 25 Nov 2009 08:16:35 GMT


 



Given that you don't know when a layout pass will be needed, this is
probably a bad solution.

There are lots of options with the layout managers -- using relative layout
and specifying the appropriate parameters to position the badge view in the
corner, using a FrameLayout to layer two children on top of each other, etc.

-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--



Other Threads

1. MapController.centerToMap(Point, boolean) is not applicable for the arguments (Point, boolean)

Any idea what is causing this?  I'm trying to use the map services
directly from another example, and the function is not recognizing the
documented arguments.

Code inside the main class is ...

@Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);

        MapView mapView = new MapView(this);
        mMapController = mapView.getController();
        mOverlayController = mapView.createOverlayController();

        mLocationManager =
(LocationManager)getSystemService(Context.LOCATION_SERVICE);

        setContentView(mapView);

        mMapController.zoomTo(15);

        updateView();

    }

    public void updateView()
    {
        android.location.Location mCurrentLocation =
        
(android.location.Location)mLocationManager.getCurrentLocation("gps");

        Double lat = mCurrentLocation.getLatitude()*1E6;
        Double lng = mCurrentLocation.getLongitude()*1E6;
        mPoint = new Point(lat.intValue(), lng.intValue());

        // This is unrecognized
        mMapController.centerMapTo(mPoint, false);

        MyLocationOverlay myLocationOverlay = new MyLocationOverlay(lat,
lng);
        mOverlayController.add(myLocationOverlay, true);
   }
--~--~---------~--~----~------------~-------~--~----~

2. How to communicate between IntentReceiver and Activity?

I had try to use AIDL, but while call Context.bindService in
IntentReceiver , there is a error dialog said cann't bind service in
IntentReceiver.
How to communicate between IntentReceiver and Activity?

I had tried use Inner-class , such as :
--code--
public class TestActivity extends Activity
{
         void foo()
         {
                do something...
         }


        Class MyIntentReceiver extends IntentReceiver
        {
        public void onReceiveIntent(Context context, Intent intent)
        {
                 foo();
        }
        }
}

--code--
AndroidMainfest.xml:
receiver android:name="android.TestActivity.MyIntentReceiver">
                <intent-filter>
                <action
android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>

But it's useless. That's why?How to solve it?
--~--~---------~--~----~------------~-------~--~----~

3. android service example

4. IM App inter thread communication

5. android bug track

6. tabhost and tabs

7. Good Luck to everyone !