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. Using Fragmentation to navigate from one activity to another

Hi,
I wanted to use fragmentation in my application. Here is the
scenario.
There are 2 vertical fragments. The 1st fragment have buttons and
second fragment have screens that need to be displayed according to
the button pressed in the 1st fragment.
I have implemented this using the help of the android sample
examples .

But now, in the 2nd fragment as well there are buttons which on
clicking, we need to navigate in this fragment from one activity(xml)
to another(xml) within the 2nd fragment. That is the 1st fragment is
always visible to the user. I have multiple xmls which need to be
navigated from one screen to another on click of buttons. But these
screens needs to be there only in the 2nd fragment as the 1st fragment
should always show same buttons from the beginning.



This is my code of my 2nd fragment class. Here the entire screen is
occupied by the activity when i click on the button.
public static class DetailsFragment extends Fragment {

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
 {
View v = (View) inflater.inflate(R.layout.testscreen, null);
Button b = (Button)v.findViewById(R.id.button1);

b.setOnClickListener(new OnClickListener()
      {

                @Override
                public void onClick(View v) {
                displayNextScreen();
        }
                        });

return v;

}

private void displayNextScreen()
{
          Intent intent = new
Intent(getActivity(),NextActivity.class);
         startActivity(intent);
}

}

Please help..

Thanks,
Priyank

-- 

2. Direct LBA access to SD card

I would like to know is there a way to read/write to LBAs within SD
card directly? If so, which APIs are available to end users?

Thx- HKT

-- 

3. Porting Android to the HTC (7) Trophy

4. Android 3D acceleration on VirtualBox

5. testing TTF on device

6. Memory Allocation

7. Any experience developing on the Huawei Ascend